Add comments + minor changes
This commit is contained in:
parent
582d8b8fc8
commit
7d82c22bc3
2 changed files with 17 additions and 12 deletions
|
@ -106,7 +106,7 @@ namespace ts {
|
|||
isOptionalParameter
|
||||
};
|
||||
|
||||
const tupleTypes: TupleType[] = [];
|
||||
const tupleTypes: GenericType[] = [];
|
||||
const unionTypes = createMap<UnionType>();
|
||||
const intersectionTypes = createMap<IntersectionType>();
|
||||
const stringLiteralTypes = createMap<LiteralType>();
|
||||
|
@ -2213,7 +2213,7 @@ namespace ts {
|
|||
}
|
||||
else if (type.target.flags & TypeFlags.Tuple) {
|
||||
writePunctuation(writer, SyntaxKind.OpenBracketToken);
|
||||
writeTypeList(type.typeArguments.slice(0, type.target.typeParameters.length), SyntaxKind.CommaToken);
|
||||
writeTypeList(type.typeArguments.slice(0, getTypeReferenceArity(type)), SyntaxKind.CommaToken);
|
||||
writePunctuation(writer, SyntaxKind.CloseBracketToken);
|
||||
}
|
||||
else {
|
||||
|
@ -4978,6 +4978,10 @@ namespace ts {
|
|||
return type;
|
||||
}
|
||||
|
||||
function getTypeReferenceArity(type: TypeReference): number {
|
||||
return type.target.typeParameters.length;
|
||||
}
|
||||
|
||||
// Get type from reference to class or interface
|
||||
function getTypeFromClassOrInterfaceReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol): Type {
|
||||
const type = <InterfaceType>getDeclaredTypeOfSymbol(getMergedSymbol(symbol));
|
||||
|
@ -5220,7 +5224,14 @@ namespace ts {
|
|||
return links.resolvedType;
|
||||
}
|
||||
|
||||
function createTupleTypeOfArity(arity: number): TupleType {
|
||||
// We represent tuple types as type references to synthesized generic interface types created by
|
||||
// this function. The types are of the form:
|
||||
//
|
||||
// interface Tuple<T0, T1, T2, ...> extends Array<T0 | T1 | T2 | ...> { 0: T0, 1: T1, 2: T2, ... }
|
||||
//
|
||||
// Note that the generic type created by this function has no symbol associated with it. The same
|
||||
// is true for each of the synthesized type parameters.
|
||||
function createTupleTypeOfArity(arity: number): GenericType {
|
||||
const typeParameters: TypeParameter[] = [];
|
||||
const properties: Symbol[] = [];
|
||||
for (let i = 0; i < arity; i++) {
|
||||
|
@ -5230,7 +5241,7 @@ namespace ts {
|
|||
property.type = typeParameter;
|
||||
properties.push(property);
|
||||
}
|
||||
const type = <TupleType & InterfaceTypeWithDeclaredMembers>createObjectType(TypeFlags.Tuple | TypeFlags.Reference);
|
||||
const type = <GenericType & InterfaceTypeWithDeclaredMembers>createObjectType(TypeFlags.Tuple | TypeFlags.Reference);
|
||||
type.typeParameters = typeParameters;
|
||||
type.outerTypeParameters = undefined;
|
||||
type.localTypeParameters = typeParameters;
|
||||
|
@ -5248,14 +5259,10 @@ namespace ts {
|
|||
return type;
|
||||
}
|
||||
|
||||
function getTupleTypeOfArity(arity: number): TupleType {
|
||||
function getTupleTypeOfArity(arity: number): GenericType {
|
||||
return tupleTypes[arity] || (tupleTypes[arity] = createTupleTypeOfArity(arity));
|
||||
}
|
||||
|
||||
function getTypeReferenceArity(type: TypeReference): number {
|
||||
return type.target.typeParameters.length;
|
||||
}
|
||||
|
||||
function createTupleType(elementTypes: Type[]) {
|
||||
return createTypeReference(getTupleTypeOfArity(elementTypes.length), elementTypes);
|
||||
}
|
||||
|
|
|
@ -2263,7 +2263,7 @@ namespace ts {
|
|||
Class = 1 << 15, // Class
|
||||
Interface = 1 << 16, // Interface
|
||||
Reference = 1 << 17, // Generic type reference
|
||||
Tuple = 1 << 18, // Tuple
|
||||
Tuple = 1 << 18, // Synthesized generic tuple type
|
||||
Union = 1 << 19, // Union (T | U)
|
||||
Intersection = 1 << 20, // Intersection (T & U)
|
||||
Anonymous = 1 << 21, // Anonymous
|
||||
|
@ -2385,8 +2385,6 @@ namespace ts {
|
|||
instantiations: Map<TypeReference>; // Generic instantiation cache
|
||||
}
|
||||
|
||||
export interface TupleType extends GenericType { }
|
||||
|
||||
export interface UnionOrIntersectionType extends Type {
|
||||
types: Type[]; // Constituent types
|
||||
/* @internal */
|
||||
|
|
Loading…
Reference in a new issue