Skip to content

Commit 5ee640d

Browse files
authored
Move utilities for getting type parameter constraints and defaults from public lazy members to services (#20162)
1 parent cb5fd53 commit 5ee640d

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ namespace ts {
251251
getSuggestionForNonexistentProperty: (node, type) => getSuggestionForNonexistentProperty(node, type),
252252
getSuggestionForNonexistentSymbol: (location, name, meaning) => getSuggestionForNonexistentSymbol(location, escapeLeadingUnderscores(name), meaning),
253253
getBaseConstraintOfType,
254+
getDefaultFromTypeParameter: type => type && type.flags & TypeFlags.TypeParameter ? getDefaultFromTypeParameter(type as TypeParameter) : undefined,
254255
resolveName(name, location, meaning) {
255256
return resolveName(location, escapeLeadingUnderscores(name), meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false);
256257
},

src/compiler/types.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,8 @@ namespace ts {
27712771
getApparentType(type: Type): Type;
27722772
getSuggestionForNonexistentProperty(node: Identifier, containingType: Type): string | undefined;
27732773
getSuggestionForNonexistentSymbol(location: Node, name: string, meaning: SymbolFlags): string | undefined;
2774-
/* @internal */ getBaseConstraintOfType(type: Type): Type | undefined;
2774+
getBaseConstraintOfType(type: Type): Type | undefined;
2775+
getDefaultFromTypeParameter(type: Type): Type | undefined;
27752776

27762777
/* @internal */ getAnyType(): Type;
27772778
/* @internal */ getStringType(): Type;
@@ -3575,15 +3576,17 @@ namespace ts {
35753576

35763577
export interface TypeVariable extends Type {
35773578
/* @internal */
3578-
resolvedBaseConstraint: Type;
3579+
resolvedBaseConstraint?: Type;
35793580
/* @internal */
3580-
resolvedIndexType: IndexType;
3581+
resolvedIndexType?: IndexType;
35813582
}
35823583

35833584
// Type parameters (TypeFlags.TypeParameter)
35843585
export interface TypeParameter extends TypeVariable {
35853586
/** Retrieve using getConstraintFromTypeParameter */
3586-
constraint: Type; // Constraint
3587+
/* @internal */
3588+
constraint?: Type; // Constraint
3589+
/* @internal */
35873590
default?: Type;
35883591
/* @internal */
35893592
target?: TypeParameter; // Instantiation target

src/services/services.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,12 @@ namespace ts {
472472
getNonNullableType(): Type {
473473
return this.checker.getNonNullableType(this);
474474
}
475+
getConstraint(): Type | undefined {
476+
return this.checker.getBaseConstraintOfType(this);
477+
}
478+
getDefault(): Type | undefined {
479+
return this.checker.getDefaultFromTypeParameter(this);
480+
}
475481
}
476482

477483
class SignatureObject implements Signature {

src/services/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ namespace ts {
5050
getNumberIndexType(): Type | undefined;
5151
getBaseTypes(): BaseType[] | undefined;
5252
getNonNullableType(): Type;
53+
getConstraint(): Type | undefined;
54+
getDefault(): Type | undefined;
5355
}
5456

5557
export interface Signature {

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,8 @@ declare namespace ts {
17831783
getApparentType(type: Type): Type;
17841784
getSuggestionForNonexistentProperty(node: Identifier, containingType: Type): string | undefined;
17851785
getSuggestionForNonexistentSymbol(location: Node, name: string, meaning: SymbolFlags): string | undefined;
1786+
getBaseConstraintOfType(type: Type): Type | undefined;
1787+
getDefaultFromTypeParameter(type: Type): Type | undefined;
17861788
}
17871789
enum NodeBuilderFlags {
17881790
None = 0,
@@ -2119,9 +2121,6 @@ declare namespace ts {
21192121
interface TypeVariable extends Type {
21202122
}
21212123
interface TypeParameter extends TypeVariable {
2122-
/** Retrieve using getConstraintFromTypeParameter */
2123-
constraint: Type;
2124-
default?: Type;
21252124
}
21262125
interface IndexedAccessType extends TypeVariable {
21272126
objectType: Type;
@@ -3843,6 +3842,8 @@ declare namespace ts {
38433842
getNumberIndexType(): Type | undefined;
38443843
getBaseTypes(): BaseType[] | undefined;
38453844
getNonNullableType(): Type;
3845+
getConstraint(): Type | undefined;
3846+
getDefault(): Type | undefined;
38463847
}
38473848
interface Signature {
38483849
getDeclaration(): SignatureDeclaration;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,8 @@ declare namespace ts {
17831783
getApparentType(type: Type): Type;
17841784
getSuggestionForNonexistentProperty(node: Identifier, containingType: Type): string | undefined;
17851785
getSuggestionForNonexistentSymbol(location: Node, name: string, meaning: SymbolFlags): string | undefined;
1786+
getBaseConstraintOfType(type: Type): Type | undefined;
1787+
getDefaultFromTypeParameter(type: Type): Type | undefined;
17861788
}
17871789
enum NodeBuilderFlags {
17881790
None = 0,
@@ -2119,9 +2121,6 @@ declare namespace ts {
21192121
interface TypeVariable extends Type {
21202122
}
21212123
interface TypeParameter extends TypeVariable {
2122-
/** Retrieve using getConstraintFromTypeParameter */
2123-
constraint: Type;
2124-
default?: Type;
21252124
}
21262125
interface IndexedAccessType extends TypeVariable {
21272126
objectType: Type;
@@ -3843,6 +3842,8 @@ declare namespace ts {
38433842
getNumberIndexType(): Type | undefined;
38443843
getBaseTypes(): BaseType[] | undefined;
38453844
getNonNullableType(): Type;
3845+
getConstraint(): Type | undefined;
3846+
getDefault(): Type | undefined;
38463847
}
38473848
interface Signature {
38483849
getDeclaration(): SignatureDeclaration;

0 commit comments

Comments
 (0)