Merge pull request #3397 from Microsoft/genericTypeAliases
Generic type aliases
This commit is contained in:
commit
acda704c05
|
@ -338,6 +338,7 @@ module ts {
|
|||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.SourceFile:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
return ContainerFlags.IsContainerWithLocals;
|
||||
|
||||
case SyntaxKind.CatchClause:
|
||||
|
@ -385,10 +386,10 @@ module ts {
|
|||
|
||||
function declareSymbolAndAddToSymbolTableWorker(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol {
|
||||
switch (container.kind) {
|
||||
// Modules, source files, and classes need specialized handling for how their
|
||||
// Modules, source files, and classes need specialized handling for how their
|
||||
// members are declared (for example, a member of a class will go into a specific
|
||||
// symbol table depending on if it is static or not). As such, we defer to
|
||||
// specialized handlers to take care of declaring these child members.
|
||||
// symbol table depending on if it is static or not). We defer to specialized
|
||||
// handlers to take care of declaring these child members.
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return declareModuleMember(node, symbolFlags, symbolExcludes);
|
||||
|
||||
|
@ -406,9 +407,10 @@ module ts {
|
|||
case SyntaxKind.ObjectLiteralExpression:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
// Interface/Object-types always have their children added to the 'members' of
|
||||
// their container. They are only accessible through an instance of their
|
||||
// container, and are never in scope otherwise (even inside the body of the
|
||||
// object / type / interface declaring them).
|
||||
// their container. They are only accessible through an instance of their
|
||||
// container, and are never in scope otherwise (even inside the body of the
|
||||
// object / type / interface declaring them). An exception is type parameters,
|
||||
// which are in scope without qualification (similar to 'locals').
|
||||
return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
|
||||
|
||||
case SyntaxKind.FunctionType:
|
||||
|
@ -424,11 +426,12 @@ module ts {
|
|||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
// All the children of these container types are never visible through another
|
||||
// symbol (i.e. through another symbol's 'exports' or 'members'). Instead,
|
||||
// they're only accessed 'lexically' (i.e. from code that exists underneath
|
||||
// symbol (i.e. through another symbol's 'exports' or 'members'). Instead,
|
||||
// they're only accessed 'lexically' (i.e. from code that exists underneath
|
||||
// their container in the tree. To accomplish this, we simply add their declared
|
||||
// symbol to the 'locals' of the container. These symbols can then be found as
|
||||
// symbol to the 'locals' of the container. These symbols can then be found as
|
||||
// the type checker walks up the containers, checking them for matching names.
|
||||
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
|
||||
}
|
||||
|
|
|
@ -1795,7 +1795,7 @@ module ts {
|
|||
function buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags) {
|
||||
let targetSymbol = getTargetSymbol(symbol);
|
||||
if (targetSymbol.flags & SymbolFlags.Class || targetSymbol.flags & SymbolFlags.Interface) {
|
||||
buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags);
|
||||
buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol), writer, enclosingDeclaraiton, flags);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2579,12 +2579,13 @@ module ts {
|
|||
return appendOuterTypeParameters(undefined, getDeclarationOfKind(symbol, kind));
|
||||
}
|
||||
|
||||
// The local type parameters are the combined set of type parameters from all declarations of the class or interface.
|
||||
function getLocalTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] {
|
||||
// The local type parameters are the combined set of type parameters from all declarations of the class,
|
||||
// interface, or type alias.
|
||||
function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol: Symbol): TypeParameter[] {
|
||||
let result: TypeParameter[];
|
||||
for (let node of symbol.declarations) {
|
||||
if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ClassDeclaration) {
|
||||
let declaration = <InterfaceDeclaration>node;
|
||||
if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.TypeAliasDeclaration) {
|
||||
let declaration = <InterfaceDeclaration | TypeAliasDeclaration>node;
|
||||
if (declaration.typeParameters) {
|
||||
result = appendTypeParameters(result, declaration.typeParameters);
|
||||
}
|
||||
|
@ -2596,7 +2597,7 @@ module ts {
|
|||
// The full set of type parameters for a generic class or interface type consists of its outer type parameters plus
|
||||
// its locally declared type parameters.
|
||||
function getTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] {
|
||||
return concatenate(getOuterTypeParametersOfClassOrInterface(symbol), getLocalTypeParametersOfClassOrInterface(symbol));
|
||||
return concatenate(getOuterTypeParametersOfClassOrInterface(symbol), getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol));
|
||||
}
|
||||
|
||||
function getBaseTypes(type: InterfaceType): ObjectType[] {
|
||||
|
@ -2669,7 +2670,7 @@ module ts {
|
|||
let kind = symbol.flags & SymbolFlags.Class ? TypeFlags.Class : TypeFlags.Interface;
|
||||
let type = links.declaredType = <InterfaceType>createObjectType(kind, symbol);
|
||||
let outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol);
|
||||
let localTypeParameters = getLocalTypeParametersOfClassOrInterface(symbol);
|
||||
let localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
|
||||
if (outerTypeParameters || localTypeParameters) {
|
||||
type.flags |= TypeFlags.Reference;
|
||||
type.typeParameters = concatenate(outerTypeParameters, localTypeParameters);
|
||||
|
@ -2694,7 +2695,16 @@ module ts {
|
|||
}
|
||||
let declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
|
||||
let type = getTypeFromTypeNode(declaration.type);
|
||||
if (!popTypeResolution()) {
|
||||
if (popTypeResolution()) {
|
||||
links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
|
||||
if (links.typeParameters) {
|
||||
// Initialize the instantiation cache for generic type aliases. The declared type corresponds to
|
||||
// an instantiation of the type alias with the type parameters supplied as type arguments.
|
||||
links.instantiations = {};
|
||||
links.instantiations[getTypeListId(links.typeParameters)] = type;
|
||||
}
|
||||
}
|
||||
else {
|
||||
type = unknownType;
|
||||
error(declaration.name, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
|
||||
}
|
||||
|
@ -3529,72 +3539,86 @@ module ts {
|
|||
}
|
||||
}
|
||||
|
||||
function getTypeFromTypeReferenceOrExpressionWithTypeArguments(node: TypeReferenceNode | ExpressionWithTypeArguments): Type {
|
||||
let links = getNodeLinks(node);
|
||||
if (!links.resolvedType) {
|
||||
let type: Type;
|
||||
|
||||
// We don't currently support heritage clauses with complex expressions in them.
|
||||
// For these cases, we just set the type to be the unknownType.
|
||||
if (node.kind !== SyntaxKind.ExpressionWithTypeArguments || isSupportedExpressionWithTypeArguments(<ExpressionWithTypeArguments>node)) {
|
||||
let typeNameOrExpression = node.kind === SyntaxKind.TypeReference
|
||||
? (<TypeReferenceNode>node).typeName
|
||||
: (<ExpressionWithTypeArguments>node).expression;
|
||||
|
||||
let symbol = resolveEntityName(typeNameOrExpression, SymbolFlags.Type);
|
||||
if (symbol) {
|
||||
if ((symbol.flags & SymbolFlags.TypeParameter) && isTypeParameterReferenceIllegalInConstraint(node, symbol)) {
|
||||
// TypeScript 1.0 spec (April 2014): 3.4.1
|
||||
// Type parameters declared in a particular type parameter list
|
||||
// may not be referenced in constraints in that type parameter list
|
||||
// Implementation: such type references are resolved to 'unknown' type that usually denotes error
|
||||
type = unknownType;
|
||||
}
|
||||
else {
|
||||
type = createTypeReferenceIfGeneric(
|
||||
getDeclaredTypeOfSymbol(symbol),
|
||||
node, node.typeArguments);
|
||||
}
|
||||
}
|
||||
// Get type from reference to class or interface
|
||||
function getTypeFromClassOrInterfaceReference(node: TypeReferenceNode | ExpressionWithTypeArguments, symbol: Symbol): Type {
|
||||
let type = getDeclaredTypeOfSymbol(symbol);
|
||||
let typeParameters = (<InterfaceType>type).localTypeParameters;
|
||||
if (typeParameters) {
|
||||
if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) {
|
||||
error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), typeParameters.length);
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
links.resolvedType = type || unknownType;
|
||||
}
|
||||
|
||||
return links.resolvedType;
|
||||
}
|
||||
|
||||
function createTypeReferenceIfGeneric(type: Type, node: Node, typeArguments: NodeArray<TypeNode>): Type {
|
||||
if (type.flags & (TypeFlags.Class | TypeFlags.Interface) && type.flags & TypeFlags.Reference) {
|
||||
// In a type reference, the outer type parameters of the referenced class or interface are automatically
|
||||
// supplied as type arguments and the type reference only specifies arguments for the local type parameters
|
||||
// of the class or interface.
|
||||
let localTypeParameters = (<InterfaceType>type).localTypeParameters;
|
||||
let expectedTypeArgCount = localTypeParameters ? localTypeParameters.length : 0;
|
||||
let typeArgCount = typeArguments ? typeArguments.length : 0;
|
||||
if (typeArgCount === expectedTypeArgCount) {
|
||||
// When no type arguments are expected we already have the right type because all outer type parameters
|
||||
// have themselves as default type arguments.
|
||||
if (typeArgCount) {
|
||||
return createTypeReference(<GenericType>type, concatenate((<InterfaceType>type).outerTypeParameters,
|
||||
map(typeArguments, getTypeFromTypeNode)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), expectedTypeArgCount);
|
||||
return undefined;
|
||||
}
|
||||
return createTypeReference(<GenericType>type, concatenate((<InterfaceType>type).outerTypeParameters,
|
||||
map(node.typeArguments, getTypeFromTypeNode)));
|
||||
}
|
||||
else {
|
||||
if (typeArguments) {
|
||||
error(node, Diagnostics.Type_0_is_not_generic, typeToString(type));
|
||||
return undefined;
|
||||
}
|
||||
if (node.typeArguments) {
|
||||
error(node, Diagnostics.Type_0_is_not_generic, typeToString(type));
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
// Get type from reference to type alias. When a type alias is generic, the declared type of the type alias may include
|
||||
// references to the type parameters of the alias. We replace those with the actual type arguments by instantiating the
|
||||
// declared type. Instantiations are cached using the type identities of the type arguments as the key.
|
||||
function getTypeFromTypeAliasReference(node: TypeReferenceNode | ExpressionWithTypeArguments, symbol: Symbol): Type {
|
||||
let type = getDeclaredTypeOfSymbol(symbol);
|
||||
let links = getSymbolLinks(symbol);
|
||||
let typeParameters = links.typeParameters;
|
||||
if (typeParameters) {
|
||||
if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) {
|
||||
error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, symbolToString(symbol), typeParameters.length);
|
||||
return unknownType;
|
||||
}
|
||||
let typeArguments = map(node.typeArguments, getTypeFromTypeNode);
|
||||
let id = getTypeListId(typeArguments);
|
||||
return links.instantiations[id] || (links.instantiations[id] = instantiateType(type, createTypeMapper(typeParameters, typeArguments)));
|
||||
}
|
||||
if (node.typeArguments) {
|
||||
error(node, Diagnostics.Type_0_is_not_generic, symbolToString(symbol));
|
||||
return unknownType;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
// Get type from reference to named type that cannot be generic (enum or type parameter)
|
||||
function getTypeFromNonGenericTypeReference(node: TypeReferenceNode | ExpressionWithTypeArguments, symbol: Symbol): Type {
|
||||
if (symbol.flags & SymbolFlags.TypeParameter && isTypeParameterReferenceIllegalInConstraint(node, symbol)) {
|
||||
// TypeScript 1.0 spec (April 2014): 3.4.1
|
||||
// Type parameters declared in a particular type parameter list
|
||||
// may not be referenced in constraints in that type parameter list
|
||||
// Implementation: such type references are resolved to 'unknown' type that usually denotes error
|
||||
return unknownType;
|
||||
}
|
||||
if (node.typeArguments) {
|
||||
error(node, Diagnostics.Type_0_is_not_generic, symbolToString(symbol));
|
||||
return unknownType;
|
||||
}
|
||||
return getDeclaredTypeOfSymbol(symbol);
|
||||
}
|
||||
|
||||
function getTypeFromTypeReference(node: TypeReferenceNode | ExpressionWithTypeArguments): Type {
|
||||
let links = getNodeLinks(node);
|
||||
if (!links.resolvedType) {
|
||||
// We only support expressions that are simple qualified names. For other expressions this produces undefined.
let typeNameOrExpression = node.kind === SyntaxKind.TypeReference ? (<TypeReferenceNode>node).typeName :
|
||||
isSupportedExpressionWithTypeArguments(<ExpressionWithTypeArguments>node) ? (<ExpressionWithTypeArguments>node).expression :
|
||||
undefined;
|
||||
let symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, SymbolFlags.Type) || unknownSymbol;
|
||||
let type = symbol === unknownSymbol ? unknownType :
|
||||
symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface) ? getTypeFromClassOrInterfaceReference(node, symbol) :
|
||||
symbol.flags & SymbolFlags.TypeAlias ? getTypeFromTypeAliasReference(node, symbol) :
|
||||
getTypeFromNonGenericTypeReference(node, symbol);
|
||||
// Cache both the resolved symbol and the resolved type. The resolved symbol is needed in when we check the
|
||||
// type reference in checkTypeReferenceOrExpressionWithTypeArguments.
|
||||
links.resolvedSymbol = symbol;
|
||||
links.resolvedType = type;
|
||||
}
|
||||
return links.resolvedType;
|
||||
}
|
||||
|
||||
function getTypeFromTypeQueryNode(node: TypeQueryNode): Type {
|
||||
let links = getNodeLinks(node);
|
||||
if (!links.resolvedType) {
|
||||
|
@ -3864,11 +3888,11 @@ module ts {
|
|||
case SyntaxKind.StringLiteral:
|
||||
return getTypeFromStringLiteral(<StringLiteral>node);
|
||||
case SyntaxKind.TypeReference:
|
||||
return getTypeFromTypeReferenceOrExpressionWithTypeArguments(<TypeReferenceNode>node);
|
||||
return getTypeFromTypeReference(<TypeReferenceNode>node);
|
||||
case SyntaxKind.TypePredicate:
|
||||
return booleanType;
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return getTypeFromTypeReferenceOrExpressionWithTypeArguments(<ExpressionWithTypeArguments>node);
|
||||
return getTypeFromTypeReference(<ExpressionWithTypeArguments>node);
|
||||
case SyntaxKind.TypeQuery:
|
||||
return getTypeFromTypeQueryNode(<TypeQueryNode>node);
|
||||
case SyntaxKind.ArrayType:
|
||||
|
@ -8953,13 +8977,15 @@ module ts {
|
|||
// Grammar checking
|
||||
checkGrammarTypeArguments(node, node.typeArguments);
|
||||
|
||||
let type = getTypeFromTypeReferenceOrExpressionWithTypeArguments(node);
|
||||
let type = getTypeFromTypeReference(node);
|
||||
if (type !== unknownType && node.typeArguments) {
|
||||
// Do type argument local checks only if referenced type is successfully resolved
|
||||
let symbol = getNodeLinks(node).resolvedSymbol;
|
||||
let typeParameters = symbol.flags & SymbolFlags.TypeAlias ? getSymbolLinks(symbol).typeParameters : (<TypeReference>type).target.localTypeParameters;
|
||||
let len = node.typeArguments.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
checkSourceElement(node.typeArguments[i]);
|
||||
let constraint = getConstraintOfTypeParameter((<TypeReference>type).target.typeParameters[i]);
|
||||
let constraint = getConstraintOfTypeParameter(typeParameters[i]);
|
||||
if (produceDiagnostics && constraint) {
|
||||
let typeArgument = (<TypeReference>type).typeArguments[i];
|
||||
checkTypeAssignableTo(typeArgument, constraint, node, Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
|
||||
|
|
|
@ -258,6 +258,7 @@ module ts {
|
|||
return visitNodes(cbNodes, node.decorators) ||
|
||||
visitNodes(cbNodes, node.modifiers) ||
|
||||
visitNode(cbNode, (<TypeAliasDeclaration>node).name) ||
|
||||
visitNodes(cbNodes, (<TypeAliasDeclaration>node).typeParameters) ||
|
||||
visitNode(cbNode, (<TypeAliasDeclaration>node).type);
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
return visitNodes(cbNodes, node.decorators) ||
|
||||
|
@ -4591,6 +4592,7 @@ module ts {
|
|||
setModifiers(node, modifiers);
|
||||
parseExpected(SyntaxKind.TypeKeyword);
|
||||
node.name = parseIdentifier();
|
||||
node.typeParameters = parseTypeParameters();
|
||||
parseExpected(SyntaxKind.EqualsToken);
|
||||
node.type = parseType();
|
||||
parseSemicolon();
|
||||
|
|
|
@ -946,6 +946,7 @@ module ts {
|
|||
|
||||
export interface TypeAliasDeclaration extends Declaration, Statement {
|
||||
name: Identifier;
|
||||
typeParameters?: NodeArray<TypeParameterDeclaration>;
|
||||
type: TypeNode;
|
||||
}
|
||||
|
||||
|
@ -1539,7 +1540,9 @@ module ts {
|
|||
export interface SymbolLinks {
|
||||
target?: Symbol; // Resolved (non-alias) target of an alias
|
||||
type?: Type; // Type of value symbol
|
||||
declaredType?: Type; // Type of class, interface, enum, or type parameter
|
||||
declaredType?: Type; // Type of class, interface, enum, type alias, or type parameter
|
||||
typeParameters?: TypeParameter[]; // Type parameters of type alias (undefined if non-generic)
|
||||
instantiations?: Map<Type>; // Instantiations of generic type alias (undefined if non-generic)
|
||||
mapper?: TypeMapper; // Type mapper for instantiation alias
|
||||
referenced?: boolean; // True if alias symbol has been referenced as a value
|
||||
unionType?: UnionType; // Containing union type for union property
|
||||
|
|
120
tests/baselines/reference/genericTypeAliases.js
Normal file
120
tests/baselines/reference/genericTypeAliases.js
Normal file
|
@ -0,0 +1,120 @@
|
|||
//// [genericTypeAliases.ts]
|
||||
type Tree<T> = T | { left: Tree<T>, right: Tree<T> };
|
||||
|
||||
var tree: Tree<number> = {
|
||||
left: {
|
||||
left: 0,
|
||||
right: {
|
||||
left: 1,
|
||||
right: 2
|
||||
},
|
||||
},
|
||||
right: 3
|
||||
};
|
||||
|
||||
type Lazy<T> = T | (() => T);
|
||||
|
||||
var ls: Lazy<string>;
|
||||
ls = "eager";
|
||||
ls = () => "lazy";
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
type Bar<U> = U | { x: Bar<U> };
|
||||
|
||||
// Deeply instantiated generics
|
||||
var x: Foo<string>;
|
||||
var y: Bar<string>;
|
||||
x = y;
|
||||
y = x;
|
||||
|
||||
x = "string";
|
||||
x = { x: "hello" };
|
||||
x = { x: { x: "world" } };
|
||||
|
||||
var z: Foo<number>;
|
||||
z = 42;
|
||||
z = { x: 42 };
|
||||
z = { x: { x: 42 } };
|
||||
|
||||
type Strange<T> = string; // Type parameter not used
|
||||
var s: Strange<number>;
|
||||
s = "hello";
|
||||
|
||||
interface Tuple<A, B> {
|
||||
a: A;
|
||||
b: B;
|
||||
}
|
||||
|
||||
type Pair<T> = Tuple<T, T>;
|
||||
|
||||
interface TaggedPair<T> extends Pair<T> {
|
||||
tag: string;
|
||||
}
|
||||
|
||||
var p: TaggedPair<number>;
|
||||
p.a = 1;
|
||||
p.b = 2;
|
||||
p.tag = "test";
|
||||
|
||||
function f<A>() {
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
var x: Foo<A[]>;
|
||||
return x;
|
||||
}
|
||||
|
||||
function g<B>() {
|
||||
type Bar<U> = U | { x: Bar<U> };
|
||||
var x: Bar<B[]>;
|
||||
return x;
|
||||
}
|
||||
|
||||
// Deeply instantiated generics
|
||||
var a = f<string>();
|
||||
var b = g<string>();
|
||||
a = b;
|
||||
|
||||
|
||||
//// [genericTypeAliases.js]
|
||||
var tree = {
|
||||
left: {
|
||||
left: 0,
|
||||
right: {
|
||||
left: 1,
|
||||
right: 2
|
||||
}
|
||||
},
|
||||
right: 3
|
||||
};
|
||||
var ls;
|
||||
ls = "eager";
|
||||
ls = function () { return "lazy"; };
|
||||
// Deeply instantiated generics
|
||||
var x;
|
||||
var y;
|
||||
x = y;
|
||||
y = x;
|
||||
x = "string";
|
||||
x = { x: "hello" };
|
||||
x = { x: { x: "world" } };
|
||||
var z;
|
||||
z = 42;
|
||||
z = { x: 42 };
|
||||
z = { x: { x: 42 } };
|
||||
var s;
|
||||
s = "hello";
|
||||
var p;
|
||||
p.a = 1;
|
||||
p.b = 2;
|
||||
p.tag = "test";
|
||||
function f() {
|
||||
var x;
|
||||
return x;
|
||||
}
|
||||
function g() {
|
||||
var x;
|
||||
return x;
|
||||
}
|
||||
// Deeply instantiated generics
|
||||
var a = f();
|
||||
var b = g();
|
||||
a = b;
|
231
tests/baselines/reference/genericTypeAliases.symbols
Normal file
231
tests/baselines/reference/genericTypeAliases.symbols
Normal file
|
@ -0,0 +1,231 @@
|
|||
=== tests/cases/conformance/types/typeAliases/genericTypeAliases.ts ===
|
||||
type Tree<T> = T | { left: Tree<T>, right: Tree<T> };
|
||||
>Tree : Symbol(Tree, Decl(genericTypeAliases.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 0, 10))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 0, 10))
|
||||
>left : Symbol(left, Decl(genericTypeAliases.ts, 0, 20))
|
||||
>Tree : Symbol(Tree, Decl(genericTypeAliases.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 0, 10))
|
||||
>right : Symbol(right, Decl(genericTypeAliases.ts, 0, 35))
|
||||
>Tree : Symbol(Tree, Decl(genericTypeAliases.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 0, 10))
|
||||
|
||||
var tree: Tree<number> = {
|
||||
>tree : Symbol(tree, Decl(genericTypeAliases.ts, 2, 3))
|
||||
>Tree : Symbol(Tree, Decl(genericTypeAliases.ts, 0, 0))
|
||||
|
||||
left: {
|
||||
>left : Symbol(left, Decl(genericTypeAliases.ts, 2, 26))
|
||||
|
||||
left: 0,
|
||||
>left : Symbol(left, Decl(genericTypeAliases.ts, 3, 11))
|
||||
|
||||
right: {
|
||||
>right : Symbol(right, Decl(genericTypeAliases.ts, 4, 16))
|
||||
|
||||
left: 1,
|
||||
>left : Symbol(left, Decl(genericTypeAliases.ts, 5, 16))
|
||||
|
||||
right: 2
|
||||
>right : Symbol(right, Decl(genericTypeAliases.ts, 6, 20))
|
||||
|
||||
},
|
||||
},
|
||||
right: 3
|
||||
>right : Symbol(right, Decl(genericTypeAliases.ts, 9, 6))
|
||||
|
||||
};
|
||||
|
||||
type Lazy<T> = T | (() => T);
|
||||
>Lazy : Symbol(Lazy, Decl(genericTypeAliases.ts, 11, 2))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 13, 10))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 13, 10))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 13, 10))
|
||||
|
||||
var ls: Lazy<string>;
|
||||
>ls : Symbol(ls, Decl(genericTypeAliases.ts, 15, 3))
|
||||
>Lazy : Symbol(Lazy, Decl(genericTypeAliases.ts, 11, 2))
|
||||
|
||||
ls = "eager";
|
||||
>ls : Symbol(ls, Decl(genericTypeAliases.ts, 15, 3))
|
||||
|
||||
ls = () => "lazy";
|
||||
>ls : Symbol(ls, Decl(genericTypeAliases.ts, 15, 3))
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
>Foo : Symbol(Foo, Decl(genericTypeAliases.ts, 17, 18))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 19, 9))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 19, 9))
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 19, 19))
|
||||
>Foo : Symbol(Foo, Decl(genericTypeAliases.ts, 17, 18))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 19, 9))
|
||||
|
||||
type Bar<U> = U | { x: Bar<U> };
|
||||
>Bar : Symbol(Bar, Decl(genericTypeAliases.ts, 19, 32))
|
||||
>U : Symbol(U, Decl(genericTypeAliases.ts, 20, 9))
|
||||
>U : Symbol(U, Decl(genericTypeAliases.ts, 20, 9))
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 20, 19))
|
||||
>Bar : Symbol(Bar, Decl(genericTypeAliases.ts, 19, 32))
|
||||
>U : Symbol(U, Decl(genericTypeAliases.ts, 20, 9))
|
||||
|
||||
// Deeply instantiated generics
|
||||
var x: Foo<string>;
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 23, 3))
|
||||
>Foo : Symbol(Foo, Decl(genericTypeAliases.ts, 17, 18))
|
||||
|
||||
var y: Bar<string>;
|
||||
>y : Symbol(y, Decl(genericTypeAliases.ts, 24, 3))
|
||||
>Bar : Symbol(Bar, Decl(genericTypeAliases.ts, 19, 32))
|
||||
|
||||
x = y;
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 23, 3))
|
||||
>y : Symbol(y, Decl(genericTypeAliases.ts, 24, 3))
|
||||
|
||||
y = x;
|
||||
>y : Symbol(y, Decl(genericTypeAliases.ts, 24, 3))
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 23, 3))
|
||||
|
||||
x = "string";
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 23, 3))
|
||||
|
||||
x = { x: "hello" };
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 23, 3))
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 29, 5))
|
||||
|
||||
x = { x: { x: "world" } };
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 23, 3))
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 30, 5))
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 30, 10))
|
||||
|
||||
var z: Foo<number>;
|
||||
>z : Symbol(z, Decl(genericTypeAliases.ts, 32, 3))
|
||||
>Foo : Symbol(Foo, Decl(genericTypeAliases.ts, 17, 18))
|
||||
|
||||
z = 42;
|
||||
>z : Symbol(z, Decl(genericTypeAliases.ts, 32, 3))
|
||||
|
||||
z = { x: 42 };
|
||||
>z : Symbol(z, Decl(genericTypeAliases.ts, 32, 3))
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 34, 5))
|
||||
|
||||
z = { x: { x: 42 } };
|
||||
>z : Symbol(z, Decl(genericTypeAliases.ts, 32, 3))
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 35, 5))
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 35, 10))
|
||||
|
||||
type Strange<T> = string; // Type parameter not used
|
||||
>Strange : Symbol(Strange, Decl(genericTypeAliases.ts, 35, 21))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 37, 13))
|
||||
|
||||
var s: Strange<number>;
|
||||
>s : Symbol(s, Decl(genericTypeAliases.ts, 38, 3))
|
||||
>Strange : Symbol(Strange, Decl(genericTypeAliases.ts, 35, 21))
|
||||
|
||||
s = "hello";
|
||||
>s : Symbol(s, Decl(genericTypeAliases.ts, 38, 3))
|
||||
|
||||
interface Tuple<A, B> {
|
||||
>Tuple : Symbol(Tuple, Decl(genericTypeAliases.ts, 39, 12))
|
||||
>A : Symbol(A, Decl(genericTypeAliases.ts, 41, 16))
|
||||
>B : Symbol(B, Decl(genericTypeAliases.ts, 41, 18))
|
||||
|
||||
a: A;
|
||||
>a : Symbol(a, Decl(genericTypeAliases.ts, 41, 23))
|
||||
>A : Symbol(A, Decl(genericTypeAliases.ts, 41, 16))
|
||||
|
||||
b: B;
|
||||
>b : Symbol(b, Decl(genericTypeAliases.ts, 42, 9))
|
||||
>B : Symbol(B, Decl(genericTypeAliases.ts, 41, 18))
|
||||
}
|
||||
|
||||
type Pair<T> = Tuple<T, T>;
|
||||
>Pair : Symbol(Pair, Decl(genericTypeAliases.ts, 44, 1))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 46, 10))
|
||||
>Tuple : Symbol(Tuple, Decl(genericTypeAliases.ts, 39, 12))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 46, 10))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 46, 10))
|
||||
|
||||
interface TaggedPair<T> extends Pair<T> {
|
||||
>TaggedPair : Symbol(TaggedPair, Decl(genericTypeAliases.ts, 46, 27))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 48, 21))
|
||||
>Pair : Symbol(Pair, Decl(genericTypeAliases.ts, 44, 1))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 48, 21))
|
||||
|
||||
tag: string;
|
||||
>tag : Symbol(tag, Decl(genericTypeAliases.ts, 48, 41))
|
||||
}
|
||||
|
||||
var p: TaggedPair<number>;
|
||||
>p : Symbol(p, Decl(genericTypeAliases.ts, 52, 3))
|
||||
>TaggedPair : Symbol(TaggedPair, Decl(genericTypeAliases.ts, 46, 27))
|
||||
|
||||
p.a = 1;
|
||||
>p.a : Symbol(Tuple.a, Decl(genericTypeAliases.ts, 41, 23))
|
||||
>p : Symbol(p, Decl(genericTypeAliases.ts, 52, 3))
|
||||
>a : Symbol(Tuple.a, Decl(genericTypeAliases.ts, 41, 23))
|
||||
|
||||
p.b = 2;
|
||||
>p.b : Symbol(Tuple.b, Decl(genericTypeAliases.ts, 42, 9))
|
||||
>p : Symbol(p, Decl(genericTypeAliases.ts, 52, 3))
|
||||
>b : Symbol(Tuple.b, Decl(genericTypeAliases.ts, 42, 9))
|
||||
|
||||
p.tag = "test";
|
||||
>p.tag : Symbol(TaggedPair.tag, Decl(genericTypeAliases.ts, 48, 41))
|
||||
>p : Symbol(p, Decl(genericTypeAliases.ts, 52, 3))
|
||||
>tag : Symbol(TaggedPair.tag, Decl(genericTypeAliases.ts, 48, 41))
|
||||
|
||||
function f<A>() {
|
||||
>f : Symbol(f, Decl(genericTypeAliases.ts, 55, 15))
|
||||
>A : Symbol(A, Decl(genericTypeAliases.ts, 57, 11))
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
>Foo : Symbol(Foo, Decl(genericTypeAliases.ts, 57, 17))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 58, 13))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 58, 13))
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 58, 23))
|
||||
>Foo : Symbol(Foo, Decl(genericTypeAliases.ts, 57, 17))
|
||||
>T : Symbol(T, Decl(genericTypeAliases.ts, 58, 13))
|
||||
|
||||
var x: Foo<A[]>;
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 59, 7))
|
||||
>Foo : Symbol(Foo, Decl(genericTypeAliases.ts, 57, 17))
|
||||
>A : Symbol(A, Decl(genericTypeAliases.ts, 57, 11))
|
||||
|
||||
return x;
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 59, 7))
|
||||
}
|
||||
|
||||
function g<B>() {
|
||||
>g : Symbol(g, Decl(genericTypeAliases.ts, 61, 1))
|
||||
>B : Symbol(B, Decl(genericTypeAliases.ts, 63, 11))
|
||||
|
||||
type Bar<U> = U | { x: Bar<U> };
|
||||
>Bar : Symbol(Bar, Decl(genericTypeAliases.ts, 63, 17))
|
||||
>U : Symbol(U, Decl(genericTypeAliases.ts, 64, 13))
|
||||
>U : Symbol(U, Decl(genericTypeAliases.ts, 64, 13))
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 64, 23))
|
||||
>Bar : Symbol(Bar, Decl(genericTypeAliases.ts, 63, 17))
|
||||
>U : Symbol(U, Decl(genericTypeAliases.ts, 64, 13))
|
||||
|
||||
var x: Bar<B[]>;
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 65, 7))
|
||||
>Bar : Symbol(Bar, Decl(genericTypeAliases.ts, 63, 17))
|
||||
>B : Symbol(B, Decl(genericTypeAliases.ts, 63, 11))
|
||||
|
||||
return x;
|
||||
>x : Symbol(x, Decl(genericTypeAliases.ts, 65, 7))
|
||||
}
|
||||
|
||||
// Deeply instantiated generics
|
||||
var a = f<string>();
|
||||
>a : Symbol(a, Decl(genericTypeAliases.ts, 70, 3))
|
||||
>f : Symbol(f, Decl(genericTypeAliases.ts, 55, 15))
|
||||
|
||||
var b = g<string>();
|
||||
>b : Symbol(b, Decl(genericTypeAliases.ts, 71, 3))
|
||||
>g : Symbol(g, Decl(genericTypeAliases.ts, 61, 1))
|
||||
|
||||
a = b;
|
||||
>a : Symbol(a, Decl(genericTypeAliases.ts, 70, 3))
|
||||
>b : Symbol(b, Decl(genericTypeAliases.ts, 71, 3))
|
||||
|
274
tests/baselines/reference/genericTypeAliases.types
Normal file
274
tests/baselines/reference/genericTypeAliases.types
Normal file
|
@ -0,0 +1,274 @@
|
|||
=== tests/cases/conformance/types/typeAliases/genericTypeAliases.ts ===
|
||||
type Tree<T> = T | { left: Tree<T>, right: Tree<T> };
|
||||
>Tree : T | { left: T | any; right: T | any; }
|
||||
>T : T
|
||||
>T : T
|
||||
>left : T | { left: T | any; right: T | any; }
|
||||
>Tree : T | { left: T | any; right: T | any; }
|
||||
>T : T
|
||||
>right : T | { left: T | any; right: T | any; }
|
||||
>Tree : T | { left: T | any; right: T | any; }
|
||||
>T : T
|
||||
|
||||
var tree: Tree<number> = {
|
||||
>tree : number | { left: number | any; right: number | any; }
|
||||
>Tree : T | { left: T | any; right: T | any; }
|
||||
>{ left: { left: 0, right: { left: 1, right: 2 }, }, right: 3} : { left: { left: number; right: { left: number; right: number; }; }; right: number; }
|
||||
|
||||
left: {
|
||||
>left : { left: number; right: { left: number; right: number; }; }
|
||||
>{ left: 0, right: { left: 1, right: 2 }, } : { left: number; right: { left: number; right: number; }; }
|
||||
|
||||
left: 0,
|
||||
>left : number
|
||||
>0 : number
|
||||
|
||||
right: {
|
||||
>right : { left: number; right: number; }
|
||||
>{ left: 1, right: 2 } : { left: number; right: number; }
|
||||
|
||||
left: 1,
|
||||
>left : number
|
||||
>1 : number
|
||||
|
||||
right: 2
|
||||
>right : number
|
||||
>2 : number
|
||||
|
||||
},
|
||||
},
|
||||
right: 3
|
||||
>right : number
|
||||
>3 : number
|
||||
|
||||
};
|
||||
|
||||
type Lazy<T> = T | (() => T);
|
||||
>Lazy : T | (() => T)
|
||||
>T : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
var ls: Lazy<string>;
|
||||
>ls : string | (() => string)
|
||||
>Lazy : T | (() => T)
|
||||
|
||||
ls = "eager";
|
||||
>ls = "eager" : string
|
||||
>ls : string | (() => string)
|
||||
>"eager" : string
|
||||
|
||||
ls = () => "lazy";
|
||||
>ls = () => "lazy" : () => string
|
||||
>ls : string | (() => string)
|
||||
>() => "lazy" : () => string
|
||||
>"lazy" : string
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
>Foo : T | { x: T | any; }
|
||||
>T : T
|
||||
>T : T
|
||||
>x : T | { x: T | any; }
|
||||
>Foo : T | { x: T | any; }
|
||||
>T : T
|
||||
|
||||
type Bar<U> = U | { x: Bar<U> };
|
||||
>Bar : U | { x: U | any; }
|
||||
>U : U
|
||||
>U : U
|
||||
>x : U | { x: U | any; }
|
||||
>Bar : U | { x: U | any; }
|
||||
>U : U
|
||||
|
||||
// Deeply instantiated generics
|
||||
var x: Foo<string>;
|
||||
>x : string | { x: string | any; }
|
||||
>Foo : T | { x: T | any; }
|
||||
|
||||
var y: Bar<string>;
|
||||
>y : string | { x: string | any; }
|
||||
>Bar : U | { x: U | any; }
|
||||
|
||||
x = y;
|
||||
>x = y : string | { x: string | any; }
|
||||
>x : string | { x: string | any; }
|
||||
>y : string | { x: string | any; }
|
||||
|
||||
y = x;
|
||||
>y = x : string | { x: string | any; }
|
||||
>y : string | { x: string | any; }
|
||||
>x : string | { x: string | any; }
|
||||
|
||||
x = "string";
|
||||
>x = "string" : string
|
||||
>x : string | { x: string | any; }
|
||||
>"string" : string
|
||||
|
||||
x = { x: "hello" };
|
||||
>x = { x: "hello" } : { x: string; }
|
||||
>x : string | { x: string | any; }
|
||||
>{ x: "hello" } : { x: string; }
|
||||
>x : string
|
||||
>"hello" : string
|
||||
|
||||
x = { x: { x: "world" } };
|
||||
>x = { x: { x: "world" } } : { x: { x: string; }; }
|
||||
>x : string | { x: string | any; }
|
||||
>{ x: { x: "world" } } : { x: { x: string; }; }
|
||||
>x : { x: string; }
|
||||
>{ x: "world" } : { x: string; }
|
||||
>x : string
|
||||
>"world" : string
|
||||
|
||||
var z: Foo<number>;
|
||||
>z : number | { x: number | any; }
|
||||
>Foo : T | { x: T | any; }
|
||||
|
||||
z = 42;
|
||||
>z = 42 : number
|
||||
>z : number | { x: number | any; }
|
||||
>42 : number
|
||||
|
||||
z = { x: 42 };
|
||||
>z = { x: 42 } : { x: number; }
|
||||
>z : number | { x: number | any; }
|
||||
>{ x: 42 } : { x: number; }
|
||||
>x : number
|
||||
>42 : number
|
||||
|
||||
z = { x: { x: 42 } };
|
||||
>z = { x: { x: 42 } } : { x: { x: number; }; }
|
||||
>z : number | { x: number | any; }
|
||||
>{ x: { x: 42 } } : { x: { x: number; }; }
|
||||
>x : { x: number; }
|
||||
>{ x: 42 } : { x: number; }
|
||||
>x : number
|
||||
>42 : number
|
||||
|
||||
type Strange<T> = string; // Type parameter not used
|
||||
>Strange : string
|
||||
>T : T
|
||||
|
||||
var s: Strange<number>;
|
||||
>s : string
|
||||
>Strange : string
|
||||
|
||||
s = "hello";
|
||||
>s = "hello" : string
|
||||
>s : string
|
||||
>"hello" : string
|
||||
|
||||
interface Tuple<A, B> {
|
||||
>Tuple : Tuple<A, B>
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
a: A;
|
||||
>a : A
|
||||
>A : A
|
||||
|
||||
b: B;
|
||||
>b : B
|
||||
>B : B
|
||||
}
|
||||
|
||||
type Pair<T> = Tuple<T, T>;
|
||||
>Pair : Tuple<T, T>
|
||||
>T : T
|
||||
>Tuple : Tuple<A, B>
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
interface TaggedPair<T> extends Pair<T> {
|
||||
>TaggedPair : TaggedPair<T>
|
||||
>T : T
|
||||
>Pair : Tuple<T, T>
|
||||
>T : T
|
||||
|
||||
tag: string;
|
||||
>tag : string
|
||||
}
|
||||
|
||||
var p: TaggedPair<number>;
|
||||
>p : TaggedPair<number>
|
||||
>TaggedPair : TaggedPair<T>
|
||||
|
||||
p.a = 1;
|
||||
>p.a = 1 : number
|
||||
>p.a : number
|
||||
>p : TaggedPair<number>
|
||||
>a : number
|
||||
>1 : number
|
||||
|
||||
p.b = 2;
|
||||
>p.b = 2 : number
|
||||
>p.b : number
|
||||
>p : TaggedPair<number>
|
||||
>b : number
|
||||
>2 : number
|
||||
|
||||
p.tag = "test";
|
||||
>p.tag = "test" : string
|
||||
>p.tag : string
|
||||
>p : TaggedPair<number>
|
||||
>tag : string
|
||||
>"test" : string
|
||||
|
||||
function f<A>() {
|
||||
>f : <A>() => A[] | { x: A[] | any; }
|
||||
>A : A
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
>Foo : T | { x: T | any; }
|
||||
>T : T
|
||||
>T : T
|
||||
>x : T | { x: T | any; }
|
||||
>Foo : T | { x: T | any; }
|
||||
>T : T
|
||||
|
||||
var x: Foo<A[]>;
|
||||
>x : A[] | { x: A[] | any; }
|
||||
>Foo : T | { x: T | any; }
|
||||
>A : A
|
||||
|
||||
return x;
|
||||
>x : A[] | { x: A[] | any; }
|
||||
}
|
||||
|
||||
function g<B>() {
|
||||
>g : <B>() => B[] | { x: B[] | any; }
|
||||
>B : B
|
||||
|
||||
type Bar<U> = U | { x: Bar<U> };
|
||||
>Bar : U | { x: U | any; }
|
||||
>U : U
|
||||
>U : U
|
||||
>x : U | { x: U | any; }
|
||||
>Bar : U | { x: U | any; }
|
||||
>U : U
|
||||
|
||||
var x: Bar<B[]>;
|
||||
>x : B[] | { x: B[] | any; }
|
||||
>Bar : U | { x: U | any; }
|
||||
>B : B
|
||||
|
||||
return x;
|
||||
>x : B[] | { x: B[] | any; }
|
||||
}
|
||||
|
||||
// Deeply instantiated generics
|
||||
var a = f<string>();
|
||||
>a : string[] | { x: string[] | any; }
|
||||
>f<string>() : string[] | { x: string[] | any; }
|
||||
>f : <A>() => A[] | { x: A[] | any; }
|
||||
|
||||
var b = g<string>();
|
||||
>b : string[] | { x: string[] | any; }
|
||||
>g<string>() : string[] | { x: string[] | any; }
|
||||
>g : <B>() => B[] | { x: B[] | any; }
|
||||
|
||||
a = b;
|
||||
>a = b : string[] | { x: string[] | any; }
|
||||
>a : string[] | { x: string[] | any; }
|
||||
>b : string[] | { x: string[] | any; }
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
tests/cases/conformance/types/specifyingTypes/typeReferences/nonGenericTypeReferenceWithTypeArguments.ts(7,9): error TS2315: Type 'C' is not generic.
|
||||
tests/cases/conformance/types/specifyingTypes/typeReferences/nonGenericTypeReferenceWithTypeArguments.ts(8,9): error TS2315: Type 'I' is not generic.
|
||||
tests/cases/conformance/types/specifyingTypes/typeReferences/nonGenericTypeReferenceWithTypeArguments.ts(9,9): error TS2315: Type 'E' is not generic.
|
||||
tests/cases/conformance/types/specifyingTypes/typeReferences/nonGenericTypeReferenceWithTypeArguments.ts(10,9): error TS2315: Type 'T' is not generic.
|
||||
tests/cases/conformance/types/specifyingTypes/typeReferences/nonGenericTypeReferenceWithTypeArguments.ts(17,13): error TS2315: Type 'C' is not generic.
|
||||
tests/cases/conformance/types/specifyingTypes/typeReferences/nonGenericTypeReferenceWithTypeArguments.ts(18,13): error TS2315: Type 'I' is not generic.
|
||||
tests/cases/conformance/types/specifyingTypes/typeReferences/nonGenericTypeReferenceWithTypeArguments.ts(19,13): error TS2315: Type 'E' is not generic.
|
||||
tests/cases/conformance/types/specifyingTypes/typeReferences/nonGenericTypeReferenceWithTypeArguments.ts(20,13): error TS2315: Type 'T' is not generic.
|
||||
tests/cases/conformance/types/specifyingTypes/typeReferences/nonGenericTypeReferenceWithTypeArguments.ts(21,13): error TS2315: Type 'U' is not generic.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/specifyingTypes/typeReferences/nonGenericTypeReferenceWithTypeArguments.ts (9 errors) ====
|
||||
// Check that errors are reported for non-generic types with type arguments
|
||||
|
||||
class C { }
|
||||
interface I { }
|
||||
enum E { }
|
||||
type T = { };
|
||||
var v1: C<string>;
|
||||
~~~~~~~~~
|
||||
!!! error TS2315: Type 'C' is not generic.
|
||||
var v2: I<string>;
|
||||
~~~~~~~~~
|
||||
!!! error TS2315: Type 'I' is not generic.
|
||||
var v3: E<string>;
|
||||
~~~~~~~~~
|
||||
!!! error TS2315: Type 'E' is not generic.
|
||||
var v4: T<string>;
|
||||
~~~~~~~~~
|
||||
!!! error TS2315: Type 'T' is not generic.
|
||||
|
||||
function f<U>() {
|
||||
class C { }
|
||||
interface I { }
|
||||
enum E { }
|
||||
type T = {};
|
||||
var v1: C<string>;
|
||||
~~~~~~~~~
|
||||
!!! error TS2315: Type 'C' is not generic.
|
||||
var v2: I<string>;
|
||||
~~~~~~~~~
|
||||
!!! error TS2315: Type 'I' is not generic.
|
||||
var v3: E<string>;
|
||||
~~~~~~~~~
|
||||
!!! error TS2315: Type 'E' is not generic.
|
||||
var v4: T<string>;
|
||||
~~~~~~~~~
|
||||
!!! error TS2315: Type 'T' is not generic.
|
||||
var v5: U<string>;
|
||||
~~~~~~~~~
|
||||
!!! error TS2315: Type 'U' is not generic.
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
//// [nonGenericTypeReferenceWithTypeArguments.ts]
|
||||
// Check that errors are reported for non-generic types with type arguments
|
||||
|
||||
class C { }
|
||||
interface I { }
|
||||
enum E { }
|
||||
type T = { };
|
||||
var v1: C<string>;
|
||||
var v2: I<string>;
|
||||
var v3: E<string>;
|
||||
var v4: T<string>;
|
||||
|
||||
function f<U>() {
|
||||
class C { }
|
||||
interface I { }
|
||||
enum E { }
|
||||
type T = {};
|
||||
var v1: C<string>;
|
||||
var v2: I<string>;
|
||||
var v3: E<string>;
|
||||
var v4: T<string>;
|
||||
var v5: U<string>;
|
||||
}
|
||||
|
||||
|
||||
//// [nonGenericTypeReferenceWithTypeArguments.js]
|
||||
// Check that errors are reported for non-generic types with type arguments
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
})();
|
||||
var E;
|
||||
(function (E) {
|
||||
})(E || (E = {}));
|
||||
var v1;
|
||||
var v2;
|
||||
var v3;
|
||||
var v4;
|
||||
function f() {
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
})();
|
||||
var E;
|
||||
(function (E) {
|
||||
})(E || (E = {}));
|
||||
var v1;
|
||||
var v2;
|
||||
var v3;
|
||||
var v4;
|
||||
var v5;
|
||||
}
|
|
@ -2,12 +2,9 @@ tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(4,22): er
|
|||
tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(5,21): error TS2422: A class may only implement another class or interface.
|
||||
tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(10,6): error TS2300: Duplicate identifier 'T2'.
|
||||
tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(11,6): error TS2300: Duplicate identifier 'T2'.
|
||||
tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(14,8): error TS1005: '=' expected.
|
||||
tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(14,12): error TS1005: '(' expected.
|
||||
tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(14,19): error TS2304: Cannot find name 'T'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts (7 errors) ====
|
||||
==== tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts (4 errors) ====
|
||||
type T1 = { x: string }
|
||||
|
||||
// An interface can be named in an extends or implements clause, but a type alias for an object type literal cannot.
|
||||
|
@ -30,10 +27,4 @@ tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(14,19): e
|
|||
|
||||
// An interface can have type parameters, but a type alias for an object type literal cannot.
|
||||
type T3<T> = { x: T }
|
||||
~
|
||||
!!! error TS1005: '=' expected.
|
||||
~
|
||||
!!! error TS1005: '(' expected.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'T'.
|
||||
|
|
@ -21,6 +21,3 @@ var C1 = (function () {
|
|||
}
|
||||
return C1;
|
||||
})();
|
||||
{
|
||||
x: T;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// Check that errors are reported for non-generic types with type arguments
|
||||
|
||||
class C { }
|
||||
interface I { }
|
||||
enum E { }
|
||||
type T = { };
|
||||
var v1: C<string>;
|
||||
var v2: I<string>;
|
||||
var v3: E<string>;
|
||||
var v4: T<string>;
|
||||
|
||||
function f<U>() {
|
||||
class C { }
|
||||
interface I { }
|
||||
enum E { }
|
||||
type T = {};
|
||||
var v1: C<string>;
|
||||
var v2: I<string>;
|
||||
var v3: E<string>;
|
||||
var v4: T<string>;
|
||||
var v5: U<string>;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
type Tree<T> = T | { left: Tree<T>, right: Tree<T> };
|
||||
|
||||
var tree: Tree<number> = {
|
||||
left: {
|
||||
left: 0,
|
||||
right: {
|
||||
left: 1,
|
||||
right: 2
|
||||
},
|
||||
},
|
||||
right: 3
|
||||
};
|
||||
|
||||
type Lazy<T> = T | (() => T);
|
||||
|
||||
var ls: Lazy<string>;
|
||||
ls = "eager";
|
||||
ls = () => "lazy";
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
type Bar<U> = U | { x: Bar<U> };
|
||||
|
||||
// Deeply instantiated generics
|
||||
var x: Foo<string>;
|
||||
var y: Bar<string>;
|
||||
x = y;
|
||||
y = x;
|
||||
|
||||
x = "string";
|
||||
x = { x: "hello" };
|
||||
x = { x: { x: "world" } };
|
||||
|
||||
var z: Foo<number>;
|
||||
z = 42;
|
||||
z = { x: 42 };
|
||||
z = { x: { x: 42 } };
|
||||
|
||||
type Strange<T> = string; // Type parameter not used
|
||||
var s: Strange<number>;
|
||||
s = "hello";
|
||||
|
||||
interface Tuple<A, B> {
|
||||
a: A;
|
||||
b: B;
|
||||
}
|
||||
|
||||
type Pair<T> = Tuple<T, T>;
|
||||
|
||||
interface TaggedPair<T> extends Pair<T> {
|
||||
tag: string;
|
||||
}
|
||||
|
||||
var p: TaggedPair<number>;
|
||||
p.a = 1;
|
||||
p.b = 2;
|
||||
p.tag = "test";
|
||||
|
||||
function f<A>() {
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
var x: Foo<A[]>;
|
||||
return x;
|
||||
}
|
||||
|
||||
function g<B>() {
|
||||
type Bar<U> = U | { x: Bar<U> };
|
||||
var x: Bar<B[]>;
|
||||
return x;
|
||||
}
|
||||
|
||||
// Deeply instantiated generics
|
||||
var a = f<string>();
|
||||
var b = g<string>();
|
||||
a = b;
|
Loading…
Reference in a new issue