Skip to content

Commit

Permalink
Merge pull request #199 from wagenet/fix-or
Browse files Browse the repository at this point in the history
Fix types for `{{or}}` helper with fallback argument
  • Loading branch information
SergeAstapov authored Sep 7, 2023
2 parents dac1476 + 2e3377d commit aa85aaa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-truth-helpers/src/helpers/or.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type FirstTruthy<T> = T extends [infer Item]
? Head
: TruthConvert<Head> extends false
? FirstTruthy<Tail>
: Head | FirstTruthy<Tail>
: NonNullable<Head> | FirstTruthy<Tail>
: undefined;

interface OrSignature<T extends MaybeTruthy[]> {
Expand Down
3 changes: 3 additions & 0 deletions packages/ember-truth-helpers/type-tests/helpers/or.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Signature {
andArg3: true;
andArg4: { isTruthy: true };
orArg: object;
stringArg: string;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
@andArg3={{and true true}}
@andArg4={{and 1 (hash isTruthy=true)}}
@orArg={{or (hash) (array)}}
@stringArg={{or this.maybeString "string"}}
/>
7 changes: 7 additions & 0 deletions packages/modern-test-app/app/components/helpers.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit aa85aaa

Please sign in to comment.