From d5b6a0bfe8549fa2dd9785440e2b3849ee0ebcb4 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 1 Apr 2022 14:56:06 -0600 Subject: [PATCH] Add tests for unions in legacy args form This is basically testing that the types supplied here do not have the problem fixed by glimmerjs/glimmer.js#390. Here, we do not have that issue, but the tests will also make sure we don't accidentally *introduce* that issue, either. --- type-tests/modifier-test.ts | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/type-tests/modifier-test.ts b/type-tests/modifier-test.ts index 9f4aa9fb..b3efaebe 100644 --- a/type-tests/modifier-test.ts +++ b/type-tests/modifier-test.ts @@ -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 {} +declare let deprecatedNamed: DeprecatedNamed; +expectTypeOf(deprecatedNamed.args.named).toEqualTypeOf< + DeprecatedNamedArgs['named'] +>(); +expectTypeOf(deprecatedNamed.args.positional).toEqualTypeOf(); + +class DeprecatedPos extends Modifier {} +declare let deprecatedPos: DeprecatedPos; +expectTypeOf(deprecatedPos.args.named).toEqualTypeOf>(); +expectTypeOf(deprecatedPos.args.positional).toEqualTypeOf< + DeprecatedPosArgs['positional'] +>(); + +class DeprecatedBoth extends Modifier {} +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 };