diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5805a496dc1..813dc5c6345 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2589,7 +2589,7 @@ namespace ts { return type; } - function createBooleanType(trueFalseTypes: Type[]): IntrinsicType & UnionType { + function createBooleanType(trueFalseTypes: ReadonlyArray): IntrinsicType & UnionType { const type = getUnionType(trueFalseTypes); type.flags |= TypeFlags.Boolean; type.intrinsicName = "boolean"; @@ -2631,7 +2631,7 @@ namespace ts { return result || emptyArray; } - function setStructuredTypeMembers(type: StructuredType, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): ResolvedType { + function setStructuredTypeMembers(type: StructuredType, members: SymbolTable, callSignatures: ReadonlyArray, constructSignatures: ReadonlyArray, stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): ResolvedType { (type).members = members; (type).properties = getNamedMembers(members); (type).callSignatures = callSignatures; @@ -2641,7 +2641,7 @@ namespace ts { return type; } - function createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): ResolvedType { + function createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: ReadonlyArray, constructSignatures: ReadonlyArray, stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): ResolvedType { return setStructuredTypeMembers(createObjectType(ObjectFlags.Anonymous, symbol), members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } @@ -3387,7 +3387,7 @@ namespace ts { } function typeReferenceToTypeNode(type: TypeReference) { - const typeArguments: Type[] = type.typeArguments || emptyArray; + const typeArguments: ReadonlyArray = type.typeArguments || emptyArray; if (type.target === globalArrayType) { if (context.flags & NodeBuilderFlags.WriteArrayAsGenericType) { const typeArgumentNode = typeToTypeNodeHelper(typeArguments[0], context); @@ -3583,7 +3583,7 @@ namespace ts { } } - function mapToTypeNodes(types: Type[] | undefined, context: NodeBuilderContext): TypeNode[] | undefined { + function mapToTypeNodes(types: ReadonlyArray | undefined, context: NodeBuilderContext): TypeNode[] | undefined { if (some(types)) { const result = []; for (const type of types) { @@ -3992,7 +3992,7 @@ namespace ts { } } - function formatUnionTypes(types: Type[]): Type[] { + function formatUnionTypes(types: ReadonlyArray): Type[] { const result: Type[] = []; let flags: TypeFlags = 0; for (let i = 0; i < types.length; i++) { @@ -5395,14 +5395,14 @@ namespace ts { return getEffectiveBaseTypeNode(type.symbol.valueDeclaration as ClassLikeDeclaration); } - function getConstructorsForTypeArguments(type: Type, typeArgumentNodes: ReadonlyArray | undefined, location: Node): Signature[] { + function getConstructorsForTypeArguments(type: Type, typeArgumentNodes: ReadonlyArray | undefined, location: Node): ReadonlyArray { const typeArgCount = length(typeArgumentNodes); const isJavaScript = isInJavaScriptFile(location); return filter(getSignaturesOfType(type, SignatureKind.Construct), sig => (isJavaScript || typeArgCount >= getMinTypeArgumentCount(sig.typeParameters)) && typeArgCount <= length(sig.typeParameters)); } - function getInstantiatedConstructorsForTypeArguments(type: Type, typeArgumentNodes: ReadonlyArray | undefined, location: Node): Signature[] { + function getInstantiatedConstructorsForTypeArguments(type: Type, typeArgumentNodes: ReadonlyArray | undefined, location: Node): ReadonlyArray { const signatures = getConstructorsForTypeArguments(type, typeArgumentNodes, location); const typeArguments = map(typeArgumentNodes, getTypeFromTypeNode); return sameMap(signatures, sig => some(sig.typeParameters) ? getSignatureInstantiation(sig, typeArguments, isInJavaScriptFile(location)) : sig); @@ -6152,11 +6152,11 @@ namespace ts { return needApparentType ? getApparentType(type) : type; } - function resolveObjectTypeMembers(type: ObjectType, source: InterfaceTypeWithDeclaredMembers, typeParameters: TypeParameter[], typeArguments: Type[]) { + function resolveObjectTypeMembers(type: ObjectType, source: InterfaceTypeWithDeclaredMembers, typeParameters: ReadonlyArray, typeArguments: ReadonlyArray) { let mapper: TypeMapper; let members: SymbolTable; - let callSignatures: Signature[]; - let constructSignatures: Signature[] | undefined; + let callSignatures: ReadonlyArray; + let constructSignatures: ReadonlyArray | undefined; let stringIndexInfo: IndexInfo | undefined; let numberIndexInfo: IndexInfo | undefined; if (rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) { @@ -6212,9 +6212,9 @@ namespace ts { function createSignature( declaration: SignatureDeclaration | JSDocSignature | undefined, - typeParameters: TypeParameter[] | undefined, + typeParameters: ReadonlyArray | undefined, thisParameter: Symbol | undefined, - parameters: Symbol[], + parameters: ReadonlyArray, resolvedReturnType: Type | undefined, resolvedTypePredicate: TypePredicate | undefined, minArgumentCount: number, @@ -6265,7 +6265,7 @@ namespace ts { return result; } - function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreThisTypes: boolean, ignoreReturnTypes: boolean): Signature | undefined { + function findMatchingSignature(signatureList: ReadonlyArray, signature: Signature, partialMatch: boolean, ignoreThisTypes: boolean, ignoreReturnTypes: boolean): Signature | undefined { for (const s of signatureList) { if (compareSignaturesIdentical(s, signature, partialMatch, ignoreThisTypes, ignoreReturnTypes, compareTypesIdentical)) { return s; @@ -6273,7 +6273,7 @@ namespace ts { } } - function findMatchingSignatures(signatureLists: Signature[][], signature: Signature, listIndex: number): Signature[] | undefined { + function findMatchingSignatures(signatureLists: ReadonlyArray>, signature: Signature, listIndex: number): Signature[] | undefined { if (signature.typeParameters) { // We require an exact match for generic signatures, so we only return signatures from the first // signature list and only if they have exact matches in the other signature lists. @@ -6303,7 +6303,7 @@ namespace ts { // Generic signatures must match exactly, but non-generic signatures are allowed to have extra optional // parameters and may differ in return types. When signatures differ in return types, the resulting return // type is the union of the constituent return types. - function getUnionSignatures(types: Type[], kind: SignatureKind): Signature[] { + function getUnionSignatures(types: ReadonlyArray, kind: SignatureKind): Signature[] { const signatureLists = map(types, t => getSignaturesOfType(t, kind)); let result: Signature[] | undefined; for (let i = 0; i < signatureLists.length; i++) { @@ -6333,7 +6333,7 @@ namespace ts { return result || emptyArray; } - function getUnionIndexInfo(types: Type[], kind: IndexKind): IndexInfo | undefined { + function getUnionIndexInfo(types: ReadonlyArray, kind: IndexKind): IndexInfo | undefined { const indexTypes: Type[] = []; let isAnyReadonly = false; for (const type of types) { @@ -6373,7 +6373,7 @@ namespace ts { getUnionType([info1.type, info2.type]), info1.isReadonly || info2.isReadonly); } - function includeMixinType(type: Type, types: Type[], index: number): Type { + function includeMixinType(type: Type, types: ReadonlyArray, index: number): Type { const mixedTypes: Type[] = []; for (let i = 0; i < types.length; i++) { if (i === index) { @@ -6389,8 +6389,8 @@ namespace ts { function resolveIntersectionTypeMembers(type: IntersectionType) { // The members and properties collections are empty for intersection types. To get all properties of an // intersection type use getPropertiesOfType (only the language service uses this). - let callSignatures: Signature[] = emptyArray; - let constructSignatures: Signature[] = emptyArray; + let callSignatures: ReadonlyArray = emptyArray; + let constructSignatures: ReadonlyArray = emptyArray; let stringIndexInfo: IndexInfo | undefined; let numberIndexInfo: IndexInfo | undefined; const types = type.types; @@ -6728,7 +6728,7 @@ namespace ts { getPropertiesOfObjectType(type); } - function getAllPossiblePropertiesOfTypes(types: Type[]): Symbol[] { + function getAllPossiblePropertiesOfTypes(types: ReadonlyArray): Symbol[] { const unionType = getUnionType(types); if (!(unionType.flags & TypeFlags.Union)) { return getAugmentedPropertiesOfType(unionType); @@ -7132,7 +7132,7 @@ namespace ts { return undefined; } - function getSignaturesOfStructuredType(type: Type, kind: SignatureKind): Signature[] { + function getSignaturesOfStructuredType(type: Type, kind: SignatureKind): ReadonlyArray { if (type.flags & TypeFlags.StructuredType) { const resolved = resolveStructuredTypeMembers(type); return kind === SignatureKind.Call ? resolved.callSignatures : resolved.constructSignatures; @@ -7144,7 +7144,7 @@ namespace ts { * Return the signatures of the given kind in the given type. Creates synthetic union signatures when necessary and * maps primitive types and type parameters are to their apparent types. */ - function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] { + function getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray { return getSignaturesOfStructuredType(getApparentType(type), kind); } @@ -7279,7 +7279,7 @@ namespace ts { * Gets the minimum number of type arguments needed to satisfy all non-optional type * parameters. */ - function getMinTypeArgumentCount(typeParameters: TypeParameter[] | undefined): number { + function getMinTypeArgumentCount(typeParameters: ReadonlyArray | undefined): number { let minTypeArgumentCount = 0; if (typeParameters) { for (let i = 0; i < typeParameters.length; i++) { @@ -7299,9 +7299,9 @@ namespace ts { * @param typeParameters The requested type parameters. * @param minTypeArgumentCount The minimum number of required type arguments. */ - function fillMissingTypeArguments(typeArguments: Type[], typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean): Type[]; - function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean): Type[] | undefined; - function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean) { + function fillMissingTypeArguments(typeArguments: Type[], typeParameters: ReadonlyArray | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean): Type[]; + function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: ReadonlyArray | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean): Type[] | undefined; + function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: ReadonlyArray | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean) { const numTypeParameters = length(typeParameters); if (numTypeParameters) { const numTypeArguments = length(typeArguments); @@ -7596,7 +7596,9 @@ namespace ts { } function getSignatureInstantiation(signature: Signature, typeArguments: Type[] | undefined, isJavascript: boolean): Signature { - typeArguments = fillMissingTypeArguments(typeArguments, signature.typeParameters, getMinTypeArgumentCount(signature.typeParameters), isJavascript)!; + return getSignatureInstantiationWithoutFillingInTypeArguments(signature, fillMissingTypeArguments(typeArguments, signature.typeParameters, getMinTypeArgumentCount(signature.typeParameters), isJavascript)); + } + function getSignatureInstantiationWithoutFillingInTypeArguments(signature: Signature, typeArguments: ReadonlyArray | undefined): Signature { const instantiations = signature.instantiations || (signature.instantiations = createMap()); const id = getTypeListId(typeArguments); let instantiation = instantiations.get(id); @@ -7606,10 +7608,10 @@ namespace ts { return instantiation; } - function createSignatureInstantiation(signature: Signature, typeArguments: Type[]): Signature { + function createSignatureInstantiation(signature: Signature, typeArguments: ReadonlyArray | undefined): Signature { return instantiateSignature(signature, createSignatureTypeMapper(signature, typeArguments), /*eraseTypeParameters*/ true); } - function createSignatureTypeMapper(signature: Signature, typeArguments: Type[]): TypeMapper { + function createSignatureTypeMapper(signature: Signature, typeArguments: ReadonlyArray | undefined): TypeMapper { return createTypeMapper(signature.typeParameters!, typeArguments); } @@ -7766,7 +7768,7 @@ namespace ts { return getSymbolOfNode(getDeclarationOfKind(typeParameter.symbol, SyntaxKind.TypeParameter)!.parent); } - function getTypeListId(types: Type[] | undefined) { + function getTypeListId(types: ReadonlyArray | undefined) { let result = ""; if (types) { const length = types.length; @@ -7794,7 +7796,7 @@ namespace ts { // It is only necessary to do so if a constituent type might be the undefined type, the null type, the type // of an object literal or the anyFunctionType. This is because there are operations in the type checker // that care about the presence of such types at arbitrary depth in a containing type. - function getPropagatingFlagsOfTypes(types: Type[], excludeKinds: TypeFlags): TypeFlags { + function getPropagatingFlagsOfTypes(types: ReadonlyArray, excludeKinds: TypeFlags): TypeFlags { let result: TypeFlags = 0; for (const type of types) { if (!(type.flags & excludeKinds)) { @@ -7804,7 +7806,7 @@ namespace ts { return result & TypeFlags.PropagatingFlags; } - function createTypeReference(target: GenericType, typeArguments: Type[] | undefined): TypeReference { + function createTypeReference(target: GenericType, typeArguments: ReadonlyArray | undefined): TypeReference { const id = getTypeListId(typeArguments); let type = target.instantiations.get(id); if (!type) { @@ -8251,7 +8253,7 @@ namespace ts { /** * Instantiates a global type that is generic with some element type, and returns that instantiation. */ - function createTypeFromGenericGlobalType(genericGlobalType: GenericType, typeArguments: Type[]): ObjectType { + function createTypeFromGenericGlobalType(genericGlobalType: GenericType, typeArguments: ReadonlyArray): ObjectType { return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, typeArguments) : emptyObjectType; } @@ -8330,7 +8332,7 @@ namespace ts { return tupleTypes[arity] || (tupleTypes[arity] = createTupleTypeOfArity(arity)); } - function createTupleType(elementTypes: Type[]) { + function createTupleType(elementTypes: ReadonlyArray) { return createTypeReference(getTupleTypeOfArity(elementTypes.length), elementTypes); } @@ -8346,7 +8348,7 @@ namespace ts { return type.id; } - function containsType(types: Type[], type: Type): boolean { + function containsType(types: ReadonlyArray, type: Type): boolean { return binarySearch(types, type, getTypeId, compareValues) >= 0; } @@ -8410,14 +8412,14 @@ namespace ts { // Add the given types to the given type set. Order is preserved, duplicates are removed, // and nested types of the given kind are flattened into the set. - function addTypesToUnion(typeSet: Type[], includes: TypeFlags, types: Type[]): TypeFlags { + function addTypesToUnion(typeSet: Type[], includes: TypeFlags, types: ReadonlyArray): TypeFlags { for (const type of types) { includes = addTypeToUnion(typeSet, includes, type); } return includes; } - function containsIdenticalType(types: Type[], type: Type) { + function containsIdenticalType(types: ReadonlyArray, type: Type) { for (const t of types) { if (isTypeIdenticalTo(t, type)) { return true; @@ -8426,7 +8428,7 @@ namespace ts { return false; } - function isSubtypeOfAny(source: Type, targets: Type[]): boolean { + function isSubtypeOfAny(source: Type, targets: ReadonlyArray): boolean { for (const target of targets) { if (source !== target && isTypeSubtypeOf(source, target) && ( !(getObjectFlags(getTargetType(source)) & ObjectFlags.Class) || @@ -8438,7 +8440,7 @@ namespace ts { return false; } - function isSetOfLiteralsFromSameEnum(types: Type[]): boolean { + function isSetOfLiteralsFromSameEnum(types: ReadonlyArray): boolean { const first = types[0]; if (first.flags & TypeFlags.EnumLiteral) { const firstEnum = getParentOfSymbol(first.symbol); @@ -8490,7 +8492,7 @@ namespace ts { // expression constructs such as array literals and the || and ?: operators). Named types can // circularly reference themselves and therefore cannot be subtype reduced during their declaration. // For example, "type Item = string | (() => Item" is a named type that circularly references itself. - function getUnionType(types: Type[], unionReduction: UnionReduction = UnionReduction.Literal, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { + function getUnionType(types: ReadonlyArray, unionReduction: UnionReduction = UnionReduction.Literal, aliasSymbol?: Symbol, aliasTypeArguments?: ReadonlyArray): Type { if (types.length === 0) { return neverType; } @@ -8557,7 +8559,7 @@ namespace ts { } // This function assumes the constituent type list is sorted and deduplicated. - function getUnionTypeFromSortedList(types: Type[], unionOfUnitTypes: TypeFlags, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { + function getUnionTypeFromSortedList(types: Type[], unionOfUnitTypes: TypeFlags, aliasSymbol?: Symbol, aliasTypeArguments?: ReadonlyArray): Type { if (types.length === 0) { return neverType; } @@ -8618,7 +8620,7 @@ namespace ts { // Add the given types to the given type set. Order is preserved, freshness is removed from literal // types, duplicates are removed, and nested types of the given kind are flattened into the set. - function addTypesToIntersection(typeSet: Type[], includes: TypeFlags, types: Type[]) { + function addTypesToIntersection(typeSet: Type[], includes: TypeFlags, types: ReadonlyArray) { for (const type of types) { includes = addTypeToIntersection(typeSet, includes, getRegularTypeOfLiteralType(type)); } @@ -8673,7 +8675,7 @@ namespace ts { // a type alias of the form "type List = T & { next: List }" cannot be reduced during its declaration. // Also, unlike union types, the order of the constituent types is preserved in order that overload resolution // for intersections of types with signatures can be deterministic. - function getIntersectionType(types: Type[], aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { + function getIntersectionType(types: ReadonlyArray, aliasSymbol?: Symbol, aliasTypeArguments?: ReadonlyArray): Type { const typeSet: Type[] = []; const includes = addTypesToIntersection(typeSet, 0, types); if (includes & TypeFlags.Never) { @@ -9576,9 +9578,9 @@ namespace ts { } } - function instantiateList(items: T[], mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): T[]; - function instantiateList(items: T[] | undefined, mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): T[] | undefined; - function instantiateList(items: T[] | undefined, mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): T[] | undefined { + function instantiateList(items: ReadonlyArray, mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): ReadonlyArray; + function instantiateList(items: ReadonlyArray | undefined, mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): ReadonlyArray | undefined; + function instantiateList(items: ReadonlyArray | undefined, mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): ReadonlyArray | undefined { if (items && items.length) { for (let i = 0; i < items.length; i++) { const item = items[i]; @@ -9596,14 +9598,14 @@ namespace ts { return items; } - function instantiateTypes(types: Type[], mapper: TypeMapper): Type[]; - function instantiateTypes(types: Type[] | undefined, mapper: TypeMapper): Type[] | undefined; - function instantiateTypes(types: Type[] | undefined, mapper: TypeMapper) { - return instantiateList(types, mapper, instantiateType); + function instantiateTypes(types: ReadonlyArray, mapper: TypeMapper): ReadonlyArray; + function instantiateTypes(types: ReadonlyArray | undefined, mapper: TypeMapper): ReadonlyArray | undefined; + function instantiateTypes(types: ReadonlyArray | undefined, mapper: TypeMapper): ReadonlyArray | undefined { + return instantiateList(types, mapper, instantiateType); } - function instantiateSignatures(signatures: Signature[], mapper: TypeMapper): Signature[] { - return instantiateList(signatures, mapper, instantiateSignature); + function instantiateSignatures(signatures: ReadonlyArray, mapper: TypeMapper): ReadonlyArray { + return instantiateList(signatures, mapper, instantiateSignature); } function makeUnaryTypeMapper(source: Type, target: Type) { @@ -9614,7 +9616,7 @@ namespace ts { return (t: Type) => t === source1 ? target1 : t === source2 ? target2 : t; } - function makeArrayTypeMapper(sources: Type[], targets: Type[] | undefined) { + function makeArrayTypeMapper(sources: ReadonlyArray, targets: ReadonlyArray | undefined) { return (t: Type) => { for (let i = 0; i < sources.length; i++) { if (t === sources[i]) { @@ -9625,14 +9627,14 @@ namespace ts { }; } - function createTypeMapper(sources: TypeParameter[], targets: Type[] | undefined): TypeMapper { + function createTypeMapper(sources: ReadonlyArray, targets: ReadonlyArray | undefined): TypeMapper { Debug.assert(targets === undefined || sources.length === targets.length); return sources.length === 1 ? makeUnaryTypeMapper(sources[0], targets ? targets[0] : anyType) : sources.length === 2 ? makeBinaryTypeMapper(sources[0], targets ? targets[0] : anyType, sources[1], targets ? targets[1] : anyType) : makeArrayTypeMapper(sources, targets); } - function createTypeEraser(sources: TypeParameter[]): TypeMapper { + function createTypeEraser(sources: ReadonlyArray): TypeMapper { return createTypeMapper(sources, /*targets*/ undefined); } @@ -9640,7 +9642,7 @@ namespace ts { * Maps forward-references to later types parameters to the empty object type. * This is used during inference when instantiating type parameter defaults. */ - function createBackreferenceMapper(typeParameters: TypeParameter[], index: number): TypeMapper { + function createBackreferenceMapper(typeParameters: ReadonlyArray, index: number): TypeMapper { return t => typeParameters.indexOf(t) >= index ? emptyObjectType : t; } @@ -12404,7 +12406,7 @@ namespace ts { } } - function createInferenceContext(typeParameters: TypeParameter[], signature: Signature | undefined, flags: InferenceFlags, compareTypes?: TypeComparer, baseInferences?: InferenceInfo[]): InferenceContext { + function createInferenceContext(typeParameters: ReadonlyArray, signature: Signature | undefined, flags: InferenceFlags, compareTypes?: TypeComparer, baseInferences?: InferenceInfo[]): InferenceContext { const inferences = baseInferences ? baseInferences.map(cloneInferenceInfo) : typeParameters.map(createInferenceInfo); const context = mapper as InferenceContext; context.typeParameters = typeParameters; @@ -14247,7 +14249,7 @@ namespace ts { if (!targetType) { // Target type is type of construct signature - let constructSignatures: Signature[] | undefined; + let constructSignatures: ReadonlyArray | undefined; if (getObjectFlags(rightType) & ObjectFlags.Interface) { constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; } @@ -16444,7 +16446,7 @@ namespace ts { return links.resolvedSymbol; } - function instantiateJsxSignatures(node: JsxOpeningLikeElement, signatures: Signature[]) { + function instantiateJsxSignatures(node: JsxOpeningLikeElement, signatures: ReadonlyArray) { const instantiatedSignatures = []; let candidateForTypeArgumentError: Signature | undefined; let hasTypeArgumentError: boolean = !!node.typeArguments; @@ -17674,7 +17676,7 @@ namespace ts { // interface B extends A { (x: 'foo'): string } // const b: B; // b('foo') // <- here overloads should be processed as [(x:'foo'): string, (x: string): void] - function reorderCandidates(signatures: Signature[], result: Signature[]): void { + function reorderCandidates(signatures: ReadonlyArray, result: Signature[]): void { let lastParent: Node | undefined; let lastSymbol: Symbol | undefined; let cutoffIndex = 0; @@ -17883,7 +17885,7 @@ namespace ts { // Above, the type of the 'value' parameter is inferred to be 'A'. const contextualSignature = getSingleCallSignature(instantiatedType); const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ? - getOrCreateTypeFromSignature(getSignatureInstantiation(contextualSignature, contextualSignature.typeParameters, isInJavaScriptFile(node))) : + getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) : instantiatedType; const inferenceTargetType = getReturnTypeOfSignature(signature); // Inferences made from return types have lower priority than all other inferences. @@ -18373,7 +18375,7 @@ namespace ts { } } - function getTypeArgumentArityError(node: Node, signatures: Signature[], typeArguments: NodeArray) { + function getTypeArgumentArityError(node: Node, signatures: ReadonlyArray, typeArguments: NodeArray) { let min = Infinity; let max = -Infinity; for (const sig of signatures) { @@ -18384,7 +18386,7 @@ namespace ts { return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, paramCount, typeArguments.length); } - function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[] | undefined, fallbackError?: DiagnosticMessage): Signature { + function resolveCall(node: CallLikeExpression, signatures: ReadonlyArray, candidatesOutArray: Signature[] | undefined, fallbackError?: DiagnosticMessage): Signature { const isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression; const isDecorator = node.kind === SyntaxKind.Decorator; const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node); @@ -18969,7 +18971,7 @@ namespace ts { * but is receiving too many arguments as part of the decorator invocation. * In those cases, a user may have meant to *call* the expression before using it as a decorator. */ - function isPotentiallyUncalledDecorator(decorator: Decorator, signatures: Signature[]) { + function isPotentiallyUncalledDecorator(decorator: Decorator, signatures: ReadonlyArray) { return signatures.length && every(signatures, signature => signature.minArgumentCount === 0 && !signature.hasRestParameter && @@ -21570,12 +21572,12 @@ namespace ts { checkDecorators(node); } - function getEffectiveTypeArguments(node: TypeReferenceNode | ExpressionWithTypeArguments, typeParameters: TypeParameter[]): Type[] { + function getEffectiveTypeArguments(node: TypeReferenceNode | ExpressionWithTypeArguments, typeParameters: ReadonlyArray): Type[] { return fillMissingTypeArguments(map(node.typeArguments!, getTypeFromTypeNode), typeParameters, getMinTypeArgumentCount(typeParameters), isInJavaScriptFile(node)); } - function checkTypeArgumentConstraints(node: TypeReferenceNode | ExpressionWithTypeArguments, typeParameters: TypeParameter[]): boolean { + function checkTypeArgumentConstraints(node: TypeReferenceNode | ExpressionWithTypeArguments, typeParameters: ReadonlyArray): boolean { let typeArguments: Type[] | undefined; let mapper: TypeMapper | undefined; let result = true; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 65856ca23f9..e8b957fe704 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2854,7 +2854,7 @@ namespace ts { getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined; - getSignaturesOfType(type: Type, kind: SignatureKind): Signature[]; + getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray; getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined; getBaseTypes(type: InterfaceType): BaseType[]; getBaseTypeOfLiteralType(type: Type): Type; @@ -3735,7 +3735,7 @@ namespace ts { symbol: Symbol; // Symbol associated with type (if any) pattern?: DestructuringPattern; // Destructuring pattern represented by type (if any) aliasSymbol?: Symbol; // Alias associated with type - aliasTypeArguments?: Type[]; // Alias type arguments (if any) + aliasTypeArguments?: ReadonlyArray; // Alias type arguments (if any) /* @internal */ wildcardInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type } @@ -3829,7 +3829,7 @@ namespace ts { */ export interface TypeReference extends ObjectType { target: GenericType; // Type reference target - typeArguments?: Type[]; // Type reference type arguments (undefined if none) + typeArguments?: ReadonlyArray; // Type reference type arguments (undefined if none) } /* @internal */ @@ -3906,8 +3906,8 @@ namespace ts { export interface ResolvedType extends ObjectType, UnionOrIntersectionType { members: SymbolTable; // Properties by name properties: Symbol[]; // Properties - callSignatures: Signature[]; // Call signatures of type - constructSignatures: Signature[]; // Construct signatures of type + callSignatures: ReadonlyArray; // Call signatures of type + constructSignatures: ReadonlyArray; // Construct signatures of type stringIndexInfo?: IndexInfo; // String indexing info numberIndexInfo?: IndexInfo; // Numeric indexing info } @@ -4032,8 +4032,8 @@ namespace ts { export interface Signature { declaration?: SignatureDeclaration | JSDocSignature; // Originating declaration - typeParameters?: TypeParameter[]; // Type parameters (undefined if non-generic) - parameters: Symbol[]; // Parameters + typeParameters?: ReadonlyArray; // Type parameters (undefined if non-generic) + parameters: ReadonlyArray; // Parameters /* @internal */ thisParameter?: Symbol; // symbol of this-type parameter /* @internal */ @@ -4132,11 +4132,11 @@ namespace ts { /* @internal */ export interface InferenceContext extends TypeMapper { - typeParameters: TypeParameter[]; // Type parameters for which inferences are made - signature?: Signature; // Generic signature for which inferences are made (if any) - inferences: InferenceInfo[]; // Inferences made for each type parameter - flags: InferenceFlags; // Inference flags - compareTypes: TypeComparer; // Type comparer function + typeParameters: ReadonlyArray; // Type parameters for which inferences are made + signature?: Signature; // Generic signature for which inferences are made (if any) + inferences: InferenceInfo[]; // Inferences made for each type parameter + flags: InferenceFlags; // Inference flags + compareTypes: TypeComparer; // Type comparer function } /* @internal */ diff --git a/src/services/services.ts b/src/services/services.ts index 24feaac17c6..2e275813585 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -391,10 +391,10 @@ namespace ts { getApparentProperties(): Symbol[] { return this.checker.getAugmentedPropertiesOfType(this); } - getCallSignatures(): Signature[] { + getCallSignatures(): ReadonlyArray { return this.checker.getSignaturesOfType(this, SignatureKind.Call); } - getConstructSignatures(): Signature[] { + getConstructSignatures(): ReadonlyArray { return this.checker.getSignaturesOfType(this, SignatureKind.Construct); } getStringIndexType(): Type | undefined { diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 2945d641c09..5eb26dc21d6 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -600,7 +600,7 @@ namespace ts.SymbolDisplay { } } - function addSignatureDisplayParts(signature: Signature, allSignatures: Signature[], flags = TypeFormatFlags.None) { + function addSignatureDisplayParts(signature: Signature, allSignatures: ReadonlyArray, flags = TypeFormatFlags.None) { addRange(displayParts, signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature)); if (allSignatures.length > 1) { displayParts.push(spacePart()); diff --git a/src/services/types.ts b/src/services/types.ts index 9ae51a4ea61..be897f20cd4 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -44,8 +44,8 @@ namespace ts { getProperties(): Symbol[]; getProperty(propertyName: string): Symbol | undefined; getApparentProperties(): Symbol[]; - getCallSignatures(): Signature[]; - getConstructSignatures(): Signature[]; + getCallSignatures(): ReadonlyArray; + getConstructSignatures(): ReadonlyArray; getStringIndexType(): Type | undefined; getNumberIndexType(): Type | undefined; getBaseTypes(): BaseType[] | undefined; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 78ad4d58c08..9ff2d42228d 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2544,7 +2544,7 @@ declare namespace ts { getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined; - getSignaturesOfType(type: Type, kind: SignatureKind): Signature[]; + getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray; getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined; getBaseTypes(type: InterfaceType): BaseType[]; getBaseTypeOfLiteralType(type: Type): Type; @@ -3246,7 +3246,7 @@ declare namespace ts { symbol: Symbol; pattern?: DestructuringPattern; aliasSymbol?: Symbol; - aliasTypeArguments?: Type[]; + aliasTypeArguments?: ReadonlyArray; wildcardInstantiation?: Type; } interface IntrinsicType extends Type { @@ -3317,7 +3317,7 @@ declare namespace ts { */ interface TypeReference extends ObjectType { target: GenericType; - typeArguments?: Type[]; + typeArguments?: ReadonlyArray; } enum Variance { Invariant = 0, @@ -3367,8 +3367,8 @@ declare namespace ts { interface ResolvedType extends ObjectType, UnionOrIntersectionType { members: SymbolTable; properties: Symbol[]; - callSignatures: Signature[]; - constructSignatures: Signature[]; + callSignatures: ReadonlyArray; + constructSignatures: ReadonlyArray; stringIndexInfo?: IndexInfo; numberIndexInfo?: IndexInfo; } @@ -3447,8 +3447,8 @@ declare namespace ts { } interface Signature { declaration?: SignatureDeclaration | JSDocSignature; - typeParameters?: TypeParameter[]; - parameters: Symbol[]; + typeParameters?: ReadonlyArray; + parameters: ReadonlyArray; thisParameter?: Symbol; resolvedReturnType?: Type; resolvedTypePredicate?: TypePredicate; @@ -3514,7 +3514,7 @@ declare namespace ts { } type TypeComparer = (s: Type, t: Type, reportErrors?: boolean) => Ternary; interface InferenceContext extends TypeMapper { - typeParameters: TypeParameter[]; + typeParameters: ReadonlyArray; signature?: Signature; inferences: InferenceInfo[]; flags: InferenceFlags; @@ -9800,8 +9800,8 @@ declare namespace ts { getProperties(): Symbol[]; getProperty(propertyName: string): Symbol | undefined; getApparentProperties(): Symbol[]; - getCallSignatures(): Signature[]; - getConstructSignatures(): Signature[]; + getCallSignatures(): ReadonlyArray; + getConstructSignatures(): ReadonlyArray; getStringIndexType(): Type | undefined; getNumberIndexType(): Type | undefined; getBaseTypes(): BaseType[] | undefined; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 8bb1efe058b..77bb50c3065 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1814,7 +1814,7 @@ declare namespace ts { getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined; - getSignaturesOfType(type: Type, kind: SignatureKind): Signature[]; + getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray; getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined; getBaseTypes(type: InterfaceType): BaseType[]; getBaseTypeOfLiteralType(type: Type): Type; @@ -2190,7 +2190,7 @@ declare namespace ts { symbol: Symbol; pattern?: DestructuringPattern; aliasSymbol?: Symbol; - aliasTypeArguments?: Type[]; + aliasTypeArguments?: ReadonlyArray; } interface LiteralType extends Type { value: string | number; @@ -2255,7 +2255,7 @@ declare namespace ts { */ interface TypeReference extends ObjectType { target: GenericType; - typeArguments?: Type[]; + typeArguments?: ReadonlyArray; } interface GenericType extends InterfaceType, TypeReference { } @@ -2315,8 +2315,8 @@ declare namespace ts { } interface Signature { declaration?: SignatureDeclaration | JSDocSignature; - typeParameters?: TypeParameter[]; - parameters: Symbol[]; + typeParameters?: ReadonlyArray; + parameters: ReadonlyArray; } enum IndexKind { String = 0, @@ -4599,8 +4599,8 @@ declare namespace ts { getProperties(): Symbol[]; getProperty(propertyName: string): Symbol | undefined; getApparentProperties(): Symbol[]; - getCallSignatures(): Signature[]; - getConstructSignatures(): Signature[]; + getCallSignatures(): ReadonlyArray; + getConstructSignatures(): ReadonlyArray; getStringIndexType(): Type | undefined; getNumberIndexType(): Type | undefined; getBaseTypes(): BaseType[] | undefined;