Skip to content

Commit 3e50f50

Browse files
author
Andy
authored
Mark some Type[] and Signature[] as ReadonlyArray (microsoft#25099)
1 parent 398b3ef commit 3e50f50

File tree

7 files changed

+103
-101
lines changed

7 files changed

+103
-101
lines changed

src/compiler/checker.ts

+69-67
Large diffs are not rendered by default.

src/compiler/types.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -2854,7 +2854,7 @@ namespace ts {
28542854
getPropertiesOfType(type: Type): Symbol[];
28552855
getPropertyOfType(type: Type, propertyName: string): Symbol | undefined;
28562856
getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined;
2857-
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
2857+
getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray<Signature>;
28582858
getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined;
28592859
getBaseTypes(type: InterfaceType): BaseType[];
28602860
getBaseTypeOfLiteralType(type: Type): Type;
@@ -3735,7 +3735,7 @@ namespace ts {
37353735
symbol: Symbol; // Symbol associated with type (if any)
37363736
pattern?: DestructuringPattern; // Destructuring pattern represented by type (if any)
37373737
aliasSymbol?: Symbol; // Alias associated with type
3738-
aliasTypeArguments?: Type[]; // Alias type arguments (if any)
3738+
aliasTypeArguments?: ReadonlyArray<Type>; // Alias type arguments (if any)
37393739
/* @internal */
37403740
wildcardInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type
37413741
}
@@ -3829,7 +3829,7 @@ namespace ts {
38293829
*/
38303830
export interface TypeReference extends ObjectType {
38313831
target: GenericType; // Type reference target
3832-
typeArguments?: Type[]; // Type reference type arguments (undefined if none)
3832+
typeArguments?: ReadonlyArray<Type>; // Type reference type arguments (undefined if none)
38333833
}
38343834

38353835
/* @internal */
@@ -3906,8 +3906,8 @@ namespace ts {
39063906
export interface ResolvedType extends ObjectType, UnionOrIntersectionType {
39073907
members: SymbolTable; // Properties by name
39083908
properties: Symbol[]; // Properties
3909-
callSignatures: Signature[]; // Call signatures of type
3910-
constructSignatures: Signature[]; // Construct signatures of type
3909+
callSignatures: ReadonlyArray<Signature>; // Call signatures of type
3910+
constructSignatures: ReadonlyArray<Signature>; // Construct signatures of type
39113911
stringIndexInfo?: IndexInfo; // String indexing info
39123912
numberIndexInfo?: IndexInfo; // Numeric indexing info
39133913
}
@@ -4032,8 +4032,8 @@ namespace ts {
40324032

40334033
export interface Signature {
40344034
declaration?: SignatureDeclaration | JSDocSignature; // Originating declaration
4035-
typeParameters?: TypeParameter[]; // Type parameters (undefined if non-generic)
4036-
parameters: Symbol[]; // Parameters
4035+
typeParameters?: ReadonlyArray<TypeParameter>; // Type parameters (undefined if non-generic)
4036+
parameters: ReadonlyArray<Symbol>; // Parameters
40374037
/* @internal */
40384038
thisParameter?: Symbol; // symbol of this-type parameter
40394039
/* @internal */
@@ -4132,11 +4132,11 @@ namespace ts {
41324132

41334133
/* @internal */
41344134
export interface InferenceContext extends TypeMapper {
4135-
typeParameters: TypeParameter[]; // Type parameters for which inferences are made
4136-
signature?: Signature; // Generic signature for which inferences are made (if any)
4137-
inferences: InferenceInfo[]; // Inferences made for each type parameter
4138-
flags: InferenceFlags; // Inference flags
4139-
compareTypes: TypeComparer; // Type comparer function
4135+
typeParameters: ReadonlyArray<TypeParameter>; // Type parameters for which inferences are made
4136+
signature?: Signature; // Generic signature for which inferences are made (if any)
4137+
inferences: InferenceInfo[]; // Inferences made for each type parameter
4138+
flags: InferenceFlags; // Inference flags
4139+
compareTypes: TypeComparer; // Type comparer function
41404140
}
41414141

41424142
/* @internal */

src/services/services.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,10 @@ namespace ts {
391391
getApparentProperties(): Symbol[] {
392392
return this.checker.getAugmentedPropertiesOfType(this);
393393
}
394-
getCallSignatures(): Signature[] {
394+
getCallSignatures(): ReadonlyArray<Signature> {
395395
return this.checker.getSignaturesOfType(this, SignatureKind.Call);
396396
}
397-
getConstructSignatures(): Signature[] {
397+
getConstructSignatures(): ReadonlyArray<Signature> {
398398
return this.checker.getSignaturesOfType(this, SignatureKind.Construct);
399399
}
400400
getStringIndexType(): Type | undefined {

src/services/symbolDisplay.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ namespace ts.SymbolDisplay {
600600
}
601601
}
602602

603-
function addSignatureDisplayParts(signature: Signature, allSignatures: Signature[], flags = TypeFormatFlags.None) {
603+
function addSignatureDisplayParts(signature: Signature, allSignatures: ReadonlyArray<Signature>, flags = TypeFormatFlags.None) {
604604
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature));
605605
if (allSignatures.length > 1) {
606606
displayParts.push(spacePart());

src/services/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ namespace ts {
4444
getProperties(): Symbol[];
4545
getProperty(propertyName: string): Symbol | undefined;
4646
getApparentProperties(): Symbol[];
47-
getCallSignatures(): Signature[];
48-
getConstructSignatures(): Signature[];
47+
getCallSignatures(): ReadonlyArray<Signature>;
48+
getConstructSignatures(): ReadonlyArray<Signature>;
4949
getStringIndexType(): Type | undefined;
5050
getNumberIndexType(): Type | undefined;
5151
getBaseTypes(): BaseType[] | undefined;

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ declare namespace ts {
25442544
getPropertiesOfType(type: Type): Symbol[];
25452545
getPropertyOfType(type: Type, propertyName: string): Symbol | undefined;
25462546
getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined;
2547-
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
2547+
getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray<Signature>;
25482548
getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined;
25492549
getBaseTypes(type: InterfaceType): BaseType[];
25502550
getBaseTypeOfLiteralType(type: Type): Type;
@@ -3246,7 +3246,7 @@ declare namespace ts {
32463246
symbol: Symbol;
32473247
pattern?: DestructuringPattern;
32483248
aliasSymbol?: Symbol;
3249-
aliasTypeArguments?: Type[];
3249+
aliasTypeArguments?: ReadonlyArray<Type>;
32503250
wildcardInstantiation?: Type;
32513251
}
32523252
interface IntrinsicType extends Type {
@@ -3317,7 +3317,7 @@ declare namespace ts {
33173317
*/
33183318
interface TypeReference extends ObjectType {
33193319
target: GenericType;
3320-
typeArguments?: Type[];
3320+
typeArguments?: ReadonlyArray<Type>;
33213321
}
33223322
enum Variance {
33233323
Invariant = 0,
@@ -3367,8 +3367,8 @@ declare namespace ts {
33673367
interface ResolvedType extends ObjectType, UnionOrIntersectionType {
33683368
members: SymbolTable;
33693369
properties: Symbol[];
3370-
callSignatures: Signature[];
3371-
constructSignatures: Signature[];
3370+
callSignatures: ReadonlyArray<Signature>;
3371+
constructSignatures: ReadonlyArray<Signature>;
33723372
stringIndexInfo?: IndexInfo;
33733373
numberIndexInfo?: IndexInfo;
33743374
}
@@ -3447,8 +3447,8 @@ declare namespace ts {
34473447
}
34483448
interface Signature {
34493449
declaration?: SignatureDeclaration | JSDocSignature;
3450-
typeParameters?: TypeParameter[];
3451-
parameters: Symbol[];
3450+
typeParameters?: ReadonlyArray<TypeParameter>;
3451+
parameters: ReadonlyArray<Symbol>;
34523452
thisParameter?: Symbol;
34533453
resolvedReturnType?: Type;
34543454
resolvedTypePredicate?: TypePredicate;
@@ -3514,7 +3514,7 @@ declare namespace ts {
35143514
}
35153515
type TypeComparer = (s: Type, t: Type, reportErrors?: boolean) => Ternary;
35163516
interface InferenceContext extends TypeMapper {
3517-
typeParameters: TypeParameter[];
3517+
typeParameters: ReadonlyArray<TypeParameter>;
35183518
signature?: Signature;
35193519
inferences: InferenceInfo[];
35203520
flags: InferenceFlags;
@@ -9800,8 +9800,8 @@ declare namespace ts {
98009800
getProperties(): Symbol[];
98019801
getProperty(propertyName: string): Symbol | undefined;
98029802
getApparentProperties(): Symbol[];
9803-
getCallSignatures(): Signature[];
9804-
getConstructSignatures(): Signature[];
9803+
getCallSignatures(): ReadonlyArray<Signature>;
9804+
getConstructSignatures(): ReadonlyArray<Signature>;
98059805
getStringIndexType(): Type | undefined;
98069806
getNumberIndexType(): Type | undefined;
98079807
getBaseTypes(): BaseType[] | undefined;

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ declare namespace ts {
18141814
getPropertiesOfType(type: Type): Symbol[];
18151815
getPropertyOfType(type: Type, propertyName: string): Symbol | undefined;
18161816
getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined;
1817-
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
1817+
getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray<Signature>;
18181818
getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined;
18191819
getBaseTypes(type: InterfaceType): BaseType[];
18201820
getBaseTypeOfLiteralType(type: Type): Type;
@@ -2190,7 +2190,7 @@ declare namespace ts {
21902190
symbol: Symbol;
21912191
pattern?: DestructuringPattern;
21922192
aliasSymbol?: Symbol;
2193-
aliasTypeArguments?: Type[];
2193+
aliasTypeArguments?: ReadonlyArray<Type>;
21942194
}
21952195
interface LiteralType extends Type {
21962196
value: string | number;
@@ -2255,7 +2255,7 @@ declare namespace ts {
22552255
*/
22562256
interface TypeReference extends ObjectType {
22572257
target: GenericType;
2258-
typeArguments?: Type[];
2258+
typeArguments?: ReadonlyArray<Type>;
22592259
}
22602260
interface GenericType extends InterfaceType, TypeReference {
22612261
}
@@ -2315,8 +2315,8 @@ declare namespace ts {
23152315
}
23162316
interface Signature {
23172317
declaration?: SignatureDeclaration | JSDocSignature;
2318-
typeParameters?: TypeParameter[];
2319-
parameters: Symbol[];
2318+
typeParameters?: ReadonlyArray<TypeParameter>;
2319+
parameters: ReadonlyArray<Symbol>;
23202320
}
23212321
enum IndexKind {
23222322
String = 0,
@@ -4599,8 +4599,8 @@ declare namespace ts {
45994599
getProperties(): Symbol[];
46004600
getProperty(propertyName: string): Symbol | undefined;
46014601
getApparentProperties(): Symbol[];
4602-
getCallSignatures(): Signature[];
4603-
getConstructSignatures(): Signature[];
4602+
getCallSignatures(): ReadonlyArray<Signature>;
4603+
getConstructSignatures(): ReadonlyArray<Signature>;
46044604
getStringIndexType(): Type | undefined;
46054605
getNumberIndexType(): Type | undefined;
46064606
getBaseTypes(): BaseType[] | undefined;

0 commit comments

Comments
 (0)