Skip to content

Commit

Permalink
Merge pull request #261 from ember-modifier/extra-tests
Browse files Browse the repository at this point in the history
Add tests for unions in legacy args form
  • Loading branch information
chriskrycho committed Apr 1, 2022
2 parents 0b911cd + d5b6a0b commit 67cf3d0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions type-tests/modifier-test.ts
Expand Up @@ -304,6 +304,46 @@ expectTypeOf(deprecatedClass).toMatchTypeOf<{
element: HTMLIFrameElement;
}>();

// Deprecated ModifierArgs form
interface DeprecatedNamedArgs {
named:
| {
name: string;
age: number;
}
| { cool: boolean; things: string[] };
}

interface DeprecatedPosArgs {
positional: [string];
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface FullDeprecatedArgs extends DeprecatedNamedArgs, DeprecatedPosArgs {}

class DeprecatedNamed extends Modifier<DeprecatedNamedArgs> {}
declare let deprecatedNamed: DeprecatedNamed;
expectTypeOf(deprecatedNamed.args.named).toEqualTypeOf<
DeprecatedNamedArgs['named']
>();
expectTypeOf(deprecatedNamed.args.positional).toEqualTypeOf<unknown[]>();

class DeprecatedPos extends Modifier<DeprecatedPosArgs> {}
declare let deprecatedPos: DeprecatedPos;
expectTypeOf(deprecatedPos.args.named).toEqualTypeOf<Record<string, unknown>>();
expectTypeOf(deprecatedPos.args.positional).toEqualTypeOf<
DeprecatedPosArgs['positional']
>();

class DeprecatedBoth extends Modifier<FullDeprecatedArgs> {}
declare let deprecatedBoth: DeprecatedBoth;
expectTypeOf(deprecatedBoth.args.named).toEqualTypeOf<
FullDeprecatedArgs['named']
>();
expectTypeOf(deprecatedBoth.args.positional).toEqualTypeOf<
FullDeprecatedArgs['positional']
>();

interface ClassBasedSignature {
Args: {
Named: { onMessage: (desc: string, data: unknown) => void };
Expand Down

0 comments on commit 67cf3d0

Please sign in to comment.