diff --git a/packages/ember-truth-helpers/src/helpers/and.ts b/packages/ember-truth-helpers/src/helpers/and.ts index 9b92e39..8158719 100644 --- a/packages/ember-truth-helpers/src/helpers/and.ts +++ b/packages/ember-truth-helpers/src/helpers/and.ts @@ -5,7 +5,7 @@ interface AndSignature { Args: { Positional: T; }; - Return: T[number]; + Return: NonNullable; } // We use class-based helper to ensure arguments are lazy-evaluated @@ -13,12 +13,12 @@ interface AndSignature { export default class AndHelper extends Helper< AndSignature > { - public compute(params: T): T[number] { + public compute(params: T): NonNullable { for (let i = 0, len = params.length; i < len; i++) { if (truthConvert(params[i]) === false) { - return params[i]; + return params[i] as NonNullable; } } - return params[params.length - 1]; + return params[params.length - 1] as NonNullable; } } diff --git a/packages/ember-truth-helpers/src/helpers/or.ts b/packages/ember-truth-helpers/src/helpers/or.ts index 5f49fb1..2e22145 100644 --- a/packages/ember-truth-helpers/src/helpers/or.ts +++ b/packages/ember-truth-helpers/src/helpers/or.ts @@ -5,7 +5,7 @@ interface OrSignature { Args: { Positional: T; }; - Return: T[number]; + Return: NonNullable; } // We use class-based helper to ensure arguments are lazy-evaluated @@ -13,12 +13,12 @@ interface OrSignature { export default class OrHelper extends Helper< OrSignature > { - public compute(params: T): T[number] { + public compute(params: T): NonNullable { for (let i = 0, len = params.length; i < len; i++) { if (truthConvert(params[i]) === true) { - return params[i]; + return params[i] as NonNullable; } } - return params[params.length - 1]; + return params[params.length - 1] as NonNullable; } } 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 869a3a4..224915a 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 @@ -3,8 +3,8 @@ import templateOnly from '@ember/component/template-only'; interface Signature { Element: HTMLDivElement; Args: { - andArg: object | boolean; - orArg: object | boolean; + andArg: object | string[]; + orArg: object | string[]; }; } diff --git a/packages/modern-test-app/app/templates/helpers.hbs b/packages/modern-test-app/app/components/helpers.hbs similarity index 63% rename from packages/modern-test-app/app/templates/helpers.hbs rename to packages/modern-test-app/app/components/helpers.hbs index 5e8257e..980794c 100644 --- a/packages/modern-test-app/app/templates/helpers.hbs +++ b/packages/modern-test-app/app/components/helpers.hbs @@ -12,6 +12,6 @@ {{xor true false}} \ 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..a1073ce --- /dev/null +++ b/packages/modern-test-app/app/components/helpers.ts @@ -0,0 +1,11 @@ +import Component from '@glimmer/component'; + +export default class extends Component { + get objectOrUndefined(): object | undefined { + return new Date().getMonth() === 7 ? { foo: 'bar' } : undefined; + } + + get arrayOrUndefined(): object | undefined { + return new Date().getMonth() === 6 ? ['foo', 'bar'] : undefined; + } +}