@@ -150,9 +150,9 @@ interface SlotsToTypes {
150
150
151
151
type SlotKey = keyof SlotsToTypes ;
152
152
153
- const globalSlots = new WeakMap ( ) ;
153
+ const globalSlots = new WeakMap < Slots [ keyof Slots ] [ 'usedBy' ] , Record < keyof Slots , Slots [ keyof Slots ] [ 'value' ] > > ( ) ;
154
154
155
- function _GetSlots ( container : Slots [ SlotKey ] [ 'usedBy' ] ) {
155
+ function _GetSlots ( container : Slots [ keyof Slots ] [ 'usedBy' ] ) {
156
156
return globalSlots . get ( container ) ;
157
157
}
158
158
@@ -161,9 +161,9 @@ const GetSlotsSymbol = Symbol.for('@@Temporal__GetSlots');
161
161
// expose GetSlots to avoid dual package hazards
162
162
( globalThis as any ) [ GetSlotsSymbol ] ||= _GetSlots ;
163
163
164
- const GetSlots = ( globalThis as any ) [ GetSlotsSymbol ] ;
164
+ const GetSlots = ( globalThis as any ) [ GetSlotsSymbol ] as typeof _GetSlots ;
165
165
166
- function _CreateSlots ( container : Slots [ SlotKey ] [ 'usedBy' ] ) : void {
166
+ function _CreateSlots ( container : Slots [ keyof Slots ] [ 'usedBy' ] ) : void {
167
167
globalSlots . set ( container , Object . create ( null ) ) ;
168
168
}
169
169
@@ -172,7 +172,7 @@ const CreateSlotsSymbol = Symbol.for('@@Temporal__CreateSlots');
172
172
// expose CreateSlots to avoid dual package hazards
173
173
( globalThis as any ) [ CreateSlotsSymbol ] ||= _CreateSlots ;
174
174
175
- export const CreateSlots = ( globalThis as any ) [ CreateSlotsSymbol ] ;
175
+ export const CreateSlots = ( globalThis as any ) [ CreateSlotsSymbol ] as typeof _CreateSlots ;
176
176
177
177
// TODO: is there a better way than 9 overloads to make HasSlot into a type
178
178
// guard that takes a variable number of parameters?
@@ -294,7 +294,7 @@ export function GetSlot<KeyT extends keyof Slots>(
294
294
container : Slots [ typeof id ] [ 'usedBy' ] ,
295
295
id : KeyT
296
296
) : Slots [ KeyT ] [ 'value' ] {
297
- const value = GetSlots ( container ) [ id ] ;
297
+ const value = GetSlots ( container ) ?. [ id ] ;
298
298
if ( value === undefined ) throw new TypeError ( `Missing internal slot ${ id } ` ) ;
299
299
return value ;
300
300
}
@@ -303,11 +303,15 @@ export function SetSlot<KeyT extends SlotKey>(
303
303
id : KeyT ,
304
304
value : Slots [ KeyT ] [ 'value' ]
305
305
) : void {
306
- const slot = GetSlots ( container ) ;
306
+ const slots = GetSlots ( container ) ;
307
307
308
- if ( id in slot ) {
308
+ if ( slots === undefined ) {
309
+ throw new TypeError ( `Missing slots for the given container` ) ;
310
+ }
311
+
312
+ if ( id in slots ) {
309
313
throw new TypeError ( `${ id } already has set` ) ;
310
314
}
311
315
312
- slot [ id ] = value ;
316
+ slots [ id ] = value ;
313
317
}
0 commit comments