diff --git a/packages/ember-truth-helpers/src/helpers/or.ts b/packages/ember-truth-helpers/src/helpers/or.ts index 629d6b4..a846406 100644 --- a/packages/ember-truth-helpers/src/helpers/or.ts +++ b/packages/ember-truth-helpers/src/helpers/or.ts @@ -11,7 +11,7 @@ type FirstTruthy = T extends [infer Item] ? Head : TruthConvert extends false ? FirstTruthy - : Head | FirstTruthy + : NonNullable | FirstTruthy : undefined; interface OrSignature { diff --git a/packages/ember-truth-helpers/type-tests/helpers/or.test.ts b/packages/ember-truth-helpers/type-tests/helpers/or.test.ts index 114387e..e58fb25 100644 --- a/packages/ember-truth-helpers/type-tests/helpers/or.test.ts +++ b/packages/ember-truth-helpers/type-tests/helpers/or.test.ts @@ -26,3 +26,6 @@ expectTypeOf(computeOr({ isTruthy: false }, 1)).toEqualTypeOf<1>(); const foo: { isTruthy: true } = { isTruthy: true }; expectTypeOf(computeOr(foo, 1)).toEqualTypeOf(foo); + +let maybeString: string | undefined; +expectTypeOf(computeOr(maybeString, 'foo')).toEqualTypeOf(); diff --git a/packages/modern-test-app/app/components/and-or-type-checking.ts b/packages/modern-test-app/app/components/and-or-type-checking.ts index 793e50e..a26b5de 100644 --- a/packages/modern-test-app/app/components/and-or-type-checking.ts +++ b/packages/modern-test-app/app/components/and-or-type-checking.ts @@ -8,6 +8,7 @@ interface Signature { andArg3: true; andArg4: { isTruthy: true }; orArg: object; + stringArg: string; }; } diff --git a/packages/modern-test-app/app/templates/helpers.hbs b/packages/modern-test-app/app/components/helpers.hbs similarity index 89% rename from packages/modern-test-app/app/templates/helpers.hbs rename to packages/modern-test-app/app/components/helpers.hbs index cc0df20..6bae4ce 100644 --- a/packages/modern-test-app/app/templates/helpers.hbs +++ b/packages/modern-test-app/app/components/helpers.hbs @@ -17,4 +17,5 @@ @andArg3={{and true true}} @andArg4={{and 1 (hash isTruthy=true)}} @orArg={{or (hash) (array)}} + @stringArg={{or this.maybeString "string"}} /> \ No newline at end of file diff --git a/packages/modern-test-app/app/components/helpers.ts b/packages/modern-test-app/app/components/helpers.ts new file mode 100644 index 0000000..da4dd2b --- /dev/null +++ b/packages/modern-test-app/app/components/helpers.ts @@ -0,0 +1,7 @@ +import Component from '@glimmer/component'; + +export default class extends Component { + get maybeString(): string | undefined { + return Date.now() === 0 ? 'now has gone' : undefined; + } +}