@@ -5950,26 +5950,18 @@ namespace ts {
5950
5950
/* @internal */
5951
5951
export interface PragmaDefinition < T1 extends string = string , T2 extends string = string , T3 extends string = string , T4 extends string = string > {
5952
5952
args ?:
5953
- | [ PragmaArgumentSpecification < T1 > ]
5954
- | [ PragmaArgumentSpecification < T1 > , PragmaArgumentSpecification < T2 > ]
5955
- | [ PragmaArgumentSpecification < T1 > , PragmaArgumentSpecification < T2 > , PragmaArgumentSpecification < T3 > ]
5956
- | [ PragmaArgumentSpecification < T1 > , PragmaArgumentSpecification < T2 > , PragmaArgumentSpecification < T3 > , PragmaArgumentSpecification < T4 > ] ;
5953
+ | readonly [ PragmaArgumentSpecification < T1 > ]
5954
+ | readonly [ PragmaArgumentSpecification < T1 > , PragmaArgumentSpecification < T2 > ]
5955
+ | readonly [ PragmaArgumentSpecification < T1 > , PragmaArgumentSpecification < T2 > , PragmaArgumentSpecification < T3 > ]
5956
+ | readonly [ PragmaArgumentSpecification < T1 > , PragmaArgumentSpecification < T2 > , PragmaArgumentSpecification < T3 > , PragmaArgumentSpecification < T4 > ] ;
5957
5957
// If not present, defaults to PragmaKindFlags.Default
5958
5958
kind ?: PragmaKindFlags ;
5959
5959
}
5960
5960
5961
- /**
5962
- * This function only exists to cause exact types to be inferred for all the literals within `commentPragmas`
5963
- */
5964
- /* @internal */
5965
- function _contextuallyTypePragmas < T extends { [ name : string ] : PragmaDefinition < K1 , K2 , K3 , K4 > } , K1 extends string , K2 extends string , K3 extends string , K4 extends string > ( args : T ) : T {
5966
- return args ;
5967
- }
5968
-
5969
5961
// While not strictly a type, this is here because `PragmaMap` needs to be here to be used with `SourceFile`, and we don't
5970
5962
// fancy effectively defining it twice, once in value-space and once in type-space
5971
5963
/* @internal */
5972
- export const commentPragmas = _contextuallyTypePragmas ( {
5964
+ export const commentPragmas = {
5973
5965
"reference" : {
5974
5966
args : [
5975
5967
{ name : "types" , optional : true , captureSpan : true } ,
@@ -5997,7 +5989,7 @@ namespace ts {
5997
5989
args : [ { name : "factory" } ] ,
5998
5990
kind : PragmaKindFlags . MultiLine
5999
5991
} ,
6000
- } ) ;
5992
+ } as const ;
6001
5993
6002
5994
/* @internal */
6003
5995
type PragmaArgTypeMaybeCapture < TDesc > = TDesc extends { captureSpan : true } ? { value : string , pos : number , end : number } : string ;
@@ -6008,29 +6000,29 @@ namespace ts {
6008
6000
? { [ K in TName ] ?: PragmaArgTypeMaybeCapture < TDesc > }
6009
6001
: { [ K in TName ] : PragmaArgTypeMaybeCapture < TDesc > } ;
6010
6002
6003
+ /* @internal */
6004
+ type UnionToIntersection < U > =
6005
+ ( U extends any ? ( k : U ) => void : never ) extends ( ( k : infer I ) => void ) ? I : never ;
6006
+
6007
+ /* @internal */
6008
+ type ArgumentDefinitionToFieldUnion < T extends readonly PragmaArgumentSpecification < any > [ ] > = {
6009
+ [ K in keyof T ] : PragmaArgTypeOptional < T [ K ] , T [ K ] extends { name : infer TName } ? TName extends string ? TName : never : never >
6010
+ } [ Extract < keyof T , number > ] ; // The mapped type maps over only the tuple members, but this reindex gets _all_ members - by extracting only `number` keys, we get only the tuple members
6011
+
6011
6012
/**
6012
6013
* Maps a pragma definition into the desired shape for its arguments object
6013
- * Maybe the below is a good argument for types being iterable on struture in some way.
6014
6014
*/
6015
6015
/* @internal */
6016
- type PragmaArgumentType < T extends PragmaDefinition > =
6017
- T extends { args : [ PragmaArgumentSpecification < infer TName1 > , PragmaArgumentSpecification < infer TName2 > , PragmaArgumentSpecification < infer TName3 > , PragmaArgumentSpecification < infer TName4 > ] }
6018
- ? PragmaArgTypeOptional < T [ "args" ] [ 0 ] , TName1 > & PragmaArgTypeOptional < T [ "args" ] [ 1 ] , TName2 > & PragmaArgTypeOptional < T [ "args" ] [ 2 ] , TName3 > & PragmaArgTypeOptional < T [ "args" ] [ 2 ] , TName4 >
6019
- : T extends { args : [ PragmaArgumentSpecification < infer TName1 > , PragmaArgumentSpecification < infer TName2 > , PragmaArgumentSpecification < infer TName3 > ] }
6020
- ? PragmaArgTypeOptional < T [ "args" ] [ 0 ] , TName1 > & PragmaArgTypeOptional < T [ "args" ] [ 1 ] , TName2 > & PragmaArgTypeOptional < T [ "args" ] [ 2 ] , TName3 >
6021
- : T extends { args : [ PragmaArgumentSpecification < infer TName1 > , PragmaArgumentSpecification < infer TName2 > ] }
6022
- ? PragmaArgTypeOptional < T [ "args" ] [ 0 ] , TName1 > & PragmaArgTypeOptional < T [ "args" ] [ 1 ] , TName2 >
6023
- : T extends { args : [ PragmaArgumentSpecification < infer TName > ] }
6024
- ? PragmaArgTypeOptional < T [ "args" ] [ 0 ] , TName >
6025
- : object ;
6026
- // The above fallback to `object` when there's no args to allow `{}` (as intended), but not the number 2, for example
6027
- // TODO: Swap to `undefined` for a cleaner API once strictNullChecks is enabled
6016
+ type PragmaArgumentType < KPrag extends keyof ConcretePragmaSpecs > =
6017
+ ConcretePragmaSpecs [ KPrag ] extends { args : readonly PragmaArgumentSpecification < any > [ ] }
6018
+ ? UnionToIntersection < ArgumentDefinitionToFieldUnion < ConcretePragmaSpecs [ KPrag ] [ "args" ] > >
6019
+ : never ;
6028
6020
6029
6021
/* @internal */
6030
6022
type ConcretePragmaSpecs = typeof commentPragmas ;
6031
6023
6032
6024
/* @internal */
6033
- export type PragmaPseudoMap = { [ K in keyof ConcretePragmaSpecs ] ? : { arguments : PragmaArgumentType < ConcretePragmaSpecs [ K ] > , range : CommentRange } } ;
6025
+ export type PragmaPseudoMap = { [ K in keyof ConcretePragmaSpecs ] : { arguments : PragmaArgumentType < K > , range : CommentRange } } ;
6034
6026
6035
6027
/* @internal */
6036
6028
export type PragmaPseudoMapEntry = { [ K in keyof PragmaPseudoMap ] : { name : K , args : PragmaPseudoMap [ K ] } } [ keyof PragmaPseudoMap ] ;
0 commit comments