|
|
|
|
@@ -2589,7 +2589,7 @@ namespace ts {
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createBooleanType(trueFalseTypes: Type[]): IntrinsicType & UnionType {
|
|
|
|
|
function createBooleanType(trueFalseTypes: ReadonlyArray<Type>): IntrinsicType & UnionType {
|
|
|
|
|
const type = <IntrinsicType & UnionType>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<Signature>, constructSignatures: ReadonlyArray<Signature>, stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): ResolvedType {
|
|
|
|
|
(<ResolvedType>type).members = members;
|
|
|
|
|
(<ResolvedType>type).properties = getNamedMembers(members);
|
|
|
|
|
(<ResolvedType>type).callSignatures = callSignatures;
|
|
|
|
|
@@ -2641,7 +2641,7 @@ namespace ts {
|
|
|
|
|
return <ResolvedType>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<Signature>, constructSignatures: ReadonlyArray<Signature>, 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> = 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<Type> | 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>): 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<TypeNode> | undefined, location: Node): Signature[] {
|
|
|
|
|
function getConstructorsForTypeArguments(type: Type, typeArgumentNodes: ReadonlyArray<TypeNode> | undefined, location: Node): ReadonlyArray<Signature> {
|
|
|
|
|
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<TypeNode> | undefined, location: Node): Signature[] {
|
|
|
|
|
function getInstantiatedConstructorsForTypeArguments(type: Type, typeArgumentNodes: ReadonlyArray<TypeNode> | undefined, location: Node): ReadonlyArray<Signature> {
|
|
|
|
|
const signatures = getConstructorsForTypeArguments(type, typeArgumentNodes, location);
|
|
|
|
|
const typeArguments = map(typeArgumentNodes, getTypeFromTypeNode);
|
|
|
|
|
return sameMap<Signature>(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<TypeParameter>, typeArguments: ReadonlyArray<Type>) {
|
|
|
|
|
let mapper: TypeMapper;
|
|
|
|
|
let members: SymbolTable;
|
|
|
|
|
let callSignatures: Signature[];
|
|
|
|
|
let constructSignatures: Signature[] | undefined;
|
|
|
|
|
let callSignatures: ReadonlyArray<Signature>;
|
|
|
|
|
let constructSignatures: ReadonlyArray<Signature> | 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<TypeParameter> | undefined,
|
|
|
|
|
thisParameter: Symbol | undefined,
|
|
|
|
|
parameters: Symbol[],
|
|
|
|
|
parameters: ReadonlyArray<Symbol>,
|
|
|
|
|
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: 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<ReadonlyArray<Signature>>, 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<Type>, 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<Type>, 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<Type>, 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<Signature> = emptyArray;
|
|
|
|
|
let constructSignatures: ReadonlyArray<Signature> = 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<Type>): 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<Signature> {
|
|
|
|
|
if (type.flags & TypeFlags.StructuredType) {
|
|
|
|
|
const resolved = resolveStructuredTypeMembers(<ObjectType>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<Signature> {
|
|
|
|
|
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<TypeParameter> | 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<TypeParameter> | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean): Type[];
|
|
|
|
|
function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: ReadonlyArray<TypeParameter> | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean): Type[] | undefined;
|
|
|
|
|
function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: ReadonlyArray<TypeParameter> | 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<Type> | undefined): Signature {
|
|
|
|
|
const instantiations = signature.instantiations || (signature.instantiations = createMap<Signature>());
|
|
|
|
|
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<Type> | undefined): Signature {
|
|
|
|
|
return instantiateSignature(signature, createSignatureTypeMapper(signature, typeArguments), /*eraseTypeParameters*/ true);
|
|
|
|
|
}
|
|
|
|
|
function createSignatureTypeMapper(signature: Signature, typeArguments: Type[]): TypeMapper {
|
|
|
|
|
function createSignatureTypeMapper(signature: Signature, typeArguments: ReadonlyArray<Type> | 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<Type> | 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<Type>, 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<Type> | 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<Type>): 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<Type>) {
|
|
|
|
|
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: 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<Type>): 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: 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<Type>): 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<Type>): 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<Type>, unionReduction: UnionReduction = UnionReduction.Literal, aliasSymbol?: Symbol, aliasTypeArguments?: ReadonlyArray<Type>): 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>): 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<Type>) {
|
|
|
|
|
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> = T & { next: List<T> }" 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<Type>, aliasSymbol?: Symbol, aliasTypeArguments?: ReadonlyArray<Type>): Type {
|
|
|
|
|
const typeSet: Type[] = [];
|
|
|
|
|
const includes = addTypesToIntersection(typeSet, 0, types);
|
|
|
|
|
if (includes & TypeFlags.Never) {
|
|
|
|
|
@@ -9576,9 +9578,9 @@ namespace ts {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function instantiateList<T>(items: T[], mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): T[];
|
|
|
|
|
function instantiateList<T>(items: T[] | undefined, mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): T[] | undefined;
|
|
|
|
|
function instantiateList<T>(items: T[] | undefined, mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): T[] | undefined {
|
|
|
|
|
function instantiateList<T>(items: ReadonlyArray<T>, mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): ReadonlyArray<T>;
|
|
|
|
|
function instantiateList<T>(items: ReadonlyArray<T> | undefined, mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): ReadonlyArray<T> | undefined;
|
|
|
|
|
function instantiateList<T>(items: ReadonlyArray<T> | undefined, mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): ReadonlyArray<T> | 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<Type>, mapper: TypeMapper): ReadonlyArray<Type>;
|
|
|
|
|
function instantiateTypes(types: ReadonlyArray<Type> | undefined, mapper: TypeMapper): ReadonlyArray<Type> | undefined;
|
|
|
|
|
function instantiateTypes(types: ReadonlyArray<Type> | undefined, mapper: TypeMapper): ReadonlyArray<Type> | undefined {
|
|
|
|
|
return instantiateList<Type>(types, mapper, instantiateType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function instantiateSignatures(signatures: Signature[], mapper: TypeMapper): Signature[] {
|
|
|
|
|
return instantiateList(signatures, mapper, instantiateSignature);
|
|
|
|
|
function instantiateSignatures(signatures: ReadonlyArray<Signature>, mapper: TypeMapper): ReadonlyArray<Signature> {
|
|
|
|
|
return instantiateList<Signature>(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<Type>, targets: ReadonlyArray<Type> | 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<TypeParameter>, targets: ReadonlyArray<Type> | 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<TypeParameter>): 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<TypeParameter>, 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<TypeParameter>, 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<Signature> | undefined;
|
|
|
|
|
if (getObjectFlags(rightType) & ObjectFlags.Interface) {
|
|
|
|
|
constructSignatures = resolveDeclaredMembers(<InterfaceType>rightType).declaredConstructSignatures;
|
|
|
|
|
}
|
|
|
|
|
@@ -16444,7 +16446,7 @@ namespace ts {
|
|
|
|
|
return links.resolvedSymbol;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function instantiateJsxSignatures(node: JsxOpeningLikeElement, signatures: Signature[]) {
|
|
|
|
|
function instantiateJsxSignatures(node: JsxOpeningLikeElement, signatures: ReadonlyArray<Signature>) {
|
|
|
|
|
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<Signature>, 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<TypeNode>) {
|
|
|
|
|
function getTypeArgumentArityError(node: Node, signatures: ReadonlyArray<Signature>, typeArguments: NodeArray<TypeNode>) {
|
|
|
|
|
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<Signature>, 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<Signature>) {
|
|
|
|
|
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<TypeParameter>): 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<TypeParameter>): boolean {
|
|
|
|
|
let typeArguments: Type[] | undefined;
|
|
|
|
|
let mapper: TypeMapper | undefined;
|
|
|
|
|
let result = true;
|
|
|
|
|
|