@@ -17,6 +17,7 @@ export function setDestroyed(component: GlimmerComponent<object>): void {
17
17
interface ArgsSetMap extends WeakMap < Args < unknown > , boolean > {
18
18
get < S > ( key : Args < S > ) : boolean | undefined ;
19
19
set < S > ( key : Args < S > , value : boolean ) : this;
20
+ has < S > ( key : Args < S > ) : boolean ;
20
21
}
21
22
22
23
// SAFETY: this only holds because we *only* acces this when `DEBUG` is `true`.
@@ -48,11 +49,13 @@ declare const Empty: unique symbol;
48
49
*/
49
50
export type EmptyObject = { [ Empty ] ?: true } ;
50
51
51
- type GetOrElse < Obj , K , Fallback > = K extends keyof Obj ? Obj [ K ] : Fallback ;
52
+ type GetOrElse < Obj , K extends PropertyKey , Fallback > = Obj extends { [ Key in K ] : infer U }
53
+ ? U
54
+ : Fallback ;
52
55
53
56
/** Given a signature `S`, get back the `Args` type. */
54
- type ArgsFor < S > = 'Args' extends keyof S
55
- ? S [ ' Args' ] extends { Named ?: object ; Positional ?: unknown [ ] } // Are they longhand already?
57
+ type ArgsFor < S > = S extends { Args : infer Args }
58
+ ? Args extends { Named ?: object ; Positional ?: unknown [ ] } // Are they longhand already?
56
59
? {
57
60
Named : GetOrElse < S [ 'Args' ] , 'Named' , EmptyObject > ;
58
61
Positional : GetOrElse < S [ 'Args' ] , 'Positional' , [ ] > ;
@@ -65,11 +68,11 @@ type _ExpandSignature<T> = {
65
68
Args : keyof T extends 'Args' | 'Element' | 'Blocks' // Is this a `Signature`?
66
69
? ArgsFor < T > // Then use `Signature` args
67
70
: { Named : T ; Positional : [ ] } ; // Otherwise fall back to classic `Args`.
68
- Blocks : 'Blocks' extends keyof T
71
+ Blocks : T extends { Blocks : infer Blocks }
69
72
? {
70
- [ Block in keyof T [ ' Blocks' ] ] : T [ ' Blocks' ] [ Block ] extends unknown [ ]
71
- ? { Params : { Positional : T [ ' Blocks' ] [ Block ] } }
72
- : T [ ' Blocks' ] [ Block ] ;
73
+ [ Block in keyof Blocks ] : Blocks [ Block ] extends unknown [ ]
74
+ ? { Params : { Positional : Blocks [ Block ] } }
75
+ : Blocks [ Block ] ;
73
76
}
74
77
: EmptyObject ;
75
78
} ;
@@ -230,8 +233,8 @@ export default class GlimmerComponent<S = unknown> {
230
233
* @param owner
231
234
* @param args
232
235
*/
233
- constructor ( _owner : unknown , args : Args < S > ) {
234
- if ( DEBUG && ! ARGS_SET . has ( args ) ) {
236
+ constructor ( owner : unknown , args : Args < S > ) {
237
+ if ( DEBUG && ! ( owner !== null && typeof owner === 'object' && ARGS_SET . has ( args ) ) ) {
235
238
throw new Error (
236
239
`You must pass both the owner and args to super() in your component: ${ this . constructor . name } . You can pass them directly, or use ...arguments to pass all arguments through.`
237
240
) ;
0 commit comments