mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-24 04:30:53 -06:00
Merge pull request #2991 from Microsoft/circularVar
Error when variable is circularly referenced in type annotation
This commit is contained in:
commit
7b860f5df0
@ -88,12 +88,11 @@ module ts {
|
||||
let undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined");
|
||||
let nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefinedOrNull, "null");
|
||||
let unknownType = createIntrinsicType(TypeFlags.Any, "unknown");
|
||||
let resolvingType = createIntrinsicType(TypeFlags.Any, "__resolving__");
|
||||
|
||||
let emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
|
||||
let anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
|
||||
let noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
|
||||
|
||||
|
||||
let anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false);
|
||||
let unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false);
|
||||
|
||||
@ -118,7 +117,7 @@ module ts {
|
||||
let getGlobalParameterDecoratorType: () => ObjectType;
|
||||
let getGlobalPropertyDecoratorType: () => ObjectType;
|
||||
let getGlobalMethodDecoratorType: () => ObjectType;
|
||||
|
||||
|
||||
let tupleTypes: Map<TupleType> = {};
|
||||
let unionTypes: Map<UnionType> = {};
|
||||
let stringLiteralTypes: Map<StringLiteralType> = {};
|
||||
@ -126,6 +125,9 @@ module ts {
|
||||
let emitDecorate = false;
|
||||
let emitParam = false;
|
||||
|
||||
let resolutionTargets: Object[] = [];
|
||||
let resolutionResults: boolean[] = [];
|
||||
|
||||
let mergedSymbols: Symbol[] = [];
|
||||
let symbolLinks: SymbolLinks[] = [];
|
||||
let nodeLinks: NodeLinks[] = [];
|
||||
@ -1980,7 +1982,7 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function collectLinkedAliases(node: Identifier): Node[]{
|
||||
function collectLinkedAliases(node: Identifier): Node[] {
|
||||
var exportSymbol: Symbol;
|
||||
if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) {
|
||||
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node);
|
||||
@ -2014,6 +2016,38 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
// Push an entry on the type resolution stack. If an entry with the given target is not already on the stack,
|
||||
// a new entry with that target and an associated result value of true is pushed on the stack, and the value
|
||||
// true is returned. Otherwise, a circularity has occurred and the result values of the existing entry and
|
||||
// all entries pushed after it are changed to false, and the value false is returned. The target object provides
|
||||
// a unique identity for a particular type resolution result: Symbol instances are used to track resolution of
|
||||
// SymbolLinks.type, SymbolLinks instances are used to track resolution of SymbolLinks.declaredType, and
|
||||
// Signature instances are used to track resolution of Signature.resolvedReturnType.
|
||||
function pushTypeResolution(target: Object): boolean {
|
||||
let i = 0;
|
||||
let count = resolutionTargets.length;
|
||||
while (i < count && resolutionTargets[i] !== target) {
|
||||
i++;
|
||||
}
|
||||
if (i < count) {
|
||||
do {
|
||||
resolutionResults[i++] = false;
|
||||
}
|
||||
while (i < count);
|
||||
return false;
|
||||
}
|
||||
resolutionTargets.push(target);
|
||||
resolutionResults.push(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Pop an entry from the type resolution stack and return its associated result value. The result value will
|
||||
// be true if no circularities were detected, or false if a circularity was found.
|
||||
function popTypeResolution(): boolean {
|
||||
resolutionTargets.pop();
|
||||
return resolutionResults.pop();
|
||||
}
|
||||
|
||||
function getRootDeclaration(node: Node): Node {
|
||||
while (node.kind === SyntaxKind.BindingElement) {
|
||||
node = node.parent.parent;
|
||||
@ -2271,20 +2305,27 @@ module ts {
|
||||
return links.type = checkExpression((<ExportAssignment>declaration).expression);
|
||||
}
|
||||
// Handle variable, parameter or property
|
||||
links.type = resolvingType;
|
||||
if (!pushTypeResolution(symbol)) {
|
||||
return unknownType;
|
||||
}
|
||||
let type = getWidenedTypeForVariableLikeDeclaration(<VariableLikeDeclaration>declaration, /*reportErrors*/ true);
|
||||
if (links.type === resolvingType) {
|
||||
links.type = type;
|
||||
}
|
||||
}
|
||||
else if (links.type === resolvingType) {
|
||||
links.type = anyType;
|
||||
if (compilerOptions.noImplicitAny) {
|
||||
let diagnostic = (<VariableLikeDeclaration>symbol.valueDeclaration).type ?
|
||||
Diagnostics._0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation :
|
||||
Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer;
|
||||
error(symbol.valueDeclaration, diagnostic, symbolToString(symbol));
|
||||
if (!popTypeResolution()) {
|
||||
if ((<VariableLikeDeclaration>symbol.valueDeclaration).type) {
|
||||
// Variable has type annotation that circularly references the variable itself
|
||||
type = unknownType;
|
||||
error(symbol.valueDeclaration, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation,
|
||||
symbolToString(symbol));
|
||||
}
|
||||
else {
|
||||
// Variable has initializer that circularly references the variable itself
|
||||
type = anyType;
|
||||
if (compilerOptions.noImplicitAny) {
|
||||
error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer,
|
||||
symbolToString(symbol));
|
||||
}
|
||||
}
|
||||
}
|
||||
links.type = type;
|
||||
}
|
||||
return links.type;
|
||||
}
|
||||
@ -2308,19 +2349,13 @@ module ts {
|
||||
|
||||
function getTypeOfAccessors(symbol: Symbol): Type {
|
||||
let links = getSymbolLinks(symbol);
|
||||
checkAndStoreTypeOfAccessors(symbol, links);
|
||||
return links.type;
|
||||
}
|
||||
|
||||
function checkAndStoreTypeOfAccessors(symbol: Symbol, links?: SymbolLinks) {
|
||||
links = links || getSymbolLinks(symbol);
|
||||
if (!links.type) {
|
||||
links.type = resolvingType;
|
||||
if (!pushTypeResolution(symbol)) {
|
||||
return unknownType;
|
||||
}
|
||||
let getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
|
||||
let setter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.SetAccessor);
|
||||
|
||||
let type: Type;
|
||||
|
||||
// First try to see if the user specified a return type on the get-accessor.
|
||||
let getterReturnType = getAnnotatedAccessorType(getter);
|
||||
if (getterReturnType) {
|
||||
@ -2342,23 +2377,20 @@ module ts {
|
||||
if (compilerOptions.noImplicitAny) {
|
||||
error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbolToString(symbol));
|
||||
}
|
||||
|
||||
type = anyType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (links.type === resolvingType) {
|
||||
links.type = type;
|
||||
}
|
||||
}
|
||||
else if (links.type === resolvingType) {
|
||||
links.type = anyType;
|
||||
if (compilerOptions.noImplicitAny) {
|
||||
let getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
|
||||
error(getter, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol));
|
||||
if (!popTypeResolution()) {
|
||||
type = anyType;
|
||||
if (compilerOptions.noImplicitAny) {
|
||||
let getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
|
||||
error(getter, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol));
|
||||
}
|
||||
}
|
||||
links.type = type;
|
||||
}
|
||||
return links.type;
|
||||
}
|
||||
|
||||
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
|
||||
@ -2451,7 +2483,7 @@ module ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function getBaseTypes(type: InterfaceType): ObjectType[]{
|
||||
function getBaseTypes(type: InterfaceType): ObjectType[] {
|
||||
let typeWithBaseTypes = <InterfaceTypeWithBaseTypes>type;
|
||||
if (!typeWithBaseTypes.baseTypes) {
|
||||
if (type.symbol.flags & SymbolFlags.Class) {
|
||||
@ -2536,17 +2568,18 @@ module ts {
|
||||
function getDeclaredTypeOfTypeAlias(symbol: Symbol): Type {
|
||||
let links = getSymbolLinks(symbol);
|
||||
if (!links.declaredType) {
|
||||
links.declaredType = resolvingType;
|
||||
// Note that we use the links object as the target here because the symbol object is used as the unique
|
||||
// identity for resolution of the 'type' property in SymbolLinks.
|
||||
if (!pushTypeResolution(links)) {
|
||||
return unknownType;
|
||||
}
|
||||
let declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
|
||||
let type = getTypeFromTypeNode(declaration.type);
|
||||
if (links.declaredType === resolvingType) {
|
||||
links.declaredType = type;
|
||||
if (!popTypeResolution()) {
|
||||
type = unknownType;
|
||||
error(declaration.name, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
|
||||
}
|
||||
}
|
||||
else if (links.declaredType === resolvingType) {
|
||||
links.declaredType = unknownType;
|
||||
let declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
|
||||
error(declaration.name, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
|
||||
links.declaredType = type;
|
||||
}
|
||||
return links.declaredType;
|
||||
}
|
||||
@ -3150,7 +3183,9 @@ module ts {
|
||||
|
||||
function getReturnTypeOfSignature(signature: Signature): Type {
|
||||
if (!signature.resolvedReturnType) {
|
||||
signature.resolvedReturnType = resolvingType;
|
||||
if (!pushTypeResolution(signature)) {
|
||||
return unknownType;
|
||||
}
|
||||
let type: Type;
|
||||
if (signature.target) {
|
||||
type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper);
|
||||
@ -3161,21 +3196,19 @@ module ts {
|
||||
else {
|
||||
type = getReturnTypeFromBody(<FunctionLikeDeclaration>signature.declaration);
|
||||
}
|
||||
if (signature.resolvedReturnType === resolvingType) {
|
||||
signature.resolvedReturnType = type;
|
||||
}
|
||||
}
|
||||
else if (signature.resolvedReturnType === resolvingType) {
|
||||
signature.resolvedReturnType = anyType;
|
||||
if (compilerOptions.noImplicitAny) {
|
||||
let declaration = <Declaration>signature.declaration;
|
||||
if (declaration.name) {
|
||||
error(declaration.name, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, declarationNameToString(declaration.name));
|
||||
}
|
||||
else {
|
||||
error(declaration, Diagnostics.Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions);
|
||||
if (!popTypeResolution()) {
|
||||
type = anyType;
|
||||
if (compilerOptions.noImplicitAny) {
|
||||
let declaration = <Declaration>signature.declaration;
|
||||
if (declaration.name) {
|
||||
error(declaration.name, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, declarationNameToString(declaration.name));
|
||||
}
|
||||
else {
|
||||
error(declaration, Diagnostics.Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions);
|
||||
}
|
||||
}
|
||||
}
|
||||
signature.resolvedReturnType = type;
|
||||
}
|
||||
return signature.resolvedReturnType;
|
||||
}
|
||||
@ -7342,10 +7375,9 @@ module ts {
|
||||
if (isContextSensitive(node)) {
|
||||
assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper);
|
||||
}
|
||||
if (!node.type) {
|
||||
signature.resolvedReturnType = resolvingType;
|
||||
if (!node.type && !signature.resolvedReturnType) {
|
||||
let returnType = getReturnTypeFromBody(node, contextualMapper);
|
||||
if (signature.resolvedReturnType === resolvingType) {
|
||||
if (!signature.resolvedReturnType) {
|
||||
signature.resolvedReturnType = returnType;
|
||||
}
|
||||
}
|
||||
@ -8359,8 +8391,7 @@ module ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkAndStoreTypeOfAccessors(getSymbolOfNode(node));
|
||||
getTypeOfAccessors(getSymbolOfNode(node));
|
||||
}
|
||||
|
||||
checkFunctionLikeDeclaration(node);
|
||||
|
||||
@ -363,6 +363,7 @@ module ts {
|
||||
An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2499, category: DiagnosticCategory.Error, key: "An interface can only extend an identifier/qualified-name with optional type arguments." },
|
||||
A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2500, category: DiagnosticCategory.Error, key: "A class can only implement an identifier/qualified-name with optional type arguments." },
|
||||
A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." },
|
||||
_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." },
|
||||
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
|
||||
@ -517,7 +518,6 @@ module ts {
|
||||
Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." },
|
||||
Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." },
|
||||
Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." },
|
||||
_0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 7021, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation." },
|
||||
_0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." },
|
||||
_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
|
||||
Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
|
||||
|
||||
@ -1440,6 +1440,10 @@
|
||||
"category": "Error",
|
||||
"code": 2501
|
||||
},
|
||||
"'{0}' is referenced directly or indirectly in its own type annotation.": {
|
||||
"category": "Error",
|
||||
"code": 2502
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
@ -2060,10 +2064,6 @@
|
||||
"category": "Error",
|
||||
"code": 7020
|
||||
},
|
||||
"'{0}' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.": {
|
||||
"category": "Error",
|
||||
"code": 7021
|
||||
},
|
||||
"'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.": {
|
||||
"category": "Error",
|
||||
"code": 7022
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(1,6): error TS2456: Type alias 'typeAlias1' circularly references itself.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(2,5): error TS2502: 'varOfAliasedType1' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(4,5): error TS2502: 'varOfAliasedType2' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(5,6): error TS2456: Type alias 'typeAlias2' circularly references itself.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts(9,6): error TS2456: Type alias 'typeAlias3' circularly references itself.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/specifyingTypes/typeQueries/circularTypeofWithVarOrFunc.ts (5 errors) ====
|
||||
type typeAlias1 = typeof varOfAliasedType1;
|
||||
~~~~~~~~~~
|
||||
!!! error TS2456: Type alias 'typeAlias1' circularly references itself.
|
||||
var varOfAliasedType1: typeAlias1;
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2502: 'varOfAliasedType1' is referenced directly or indirectly in its own type annotation.
|
||||
|
||||
var varOfAliasedType2: typeAlias2;
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2502: 'varOfAliasedType2' is referenced directly or indirectly in its own type annotation.
|
||||
type typeAlias2 = typeof varOfAliasedType2;
|
||||
~~~~~~~~~~
|
||||
!!! error TS2456: Type alias 'typeAlias2' circularly references itself.
|
||||
|
||||
function func(): typeAlias3 { return null; }
|
||||
var varOfAliasedType3 = func();
|
||||
type typeAlias3 = typeof varOfAliasedType3;
|
||||
~~~~~~~~~~
|
||||
!!! error TS2456: Type alias 'typeAlias3' circularly references itself.
|
||||
|
||||
17
tests/baselines/reference/circularTypeofWithVarOrFunc.js
Normal file
17
tests/baselines/reference/circularTypeofWithVarOrFunc.js
Normal file
@ -0,0 +1,17 @@
|
||||
//// [circularTypeofWithVarOrFunc.ts]
|
||||
type typeAlias1 = typeof varOfAliasedType1;
|
||||
var varOfAliasedType1: typeAlias1;
|
||||
|
||||
var varOfAliasedType2: typeAlias2;
|
||||
type typeAlias2 = typeof varOfAliasedType2;
|
||||
|
||||
function func(): typeAlias3 { return null; }
|
||||
var varOfAliasedType3 = func();
|
||||
type typeAlias3 = typeof varOfAliasedType3;
|
||||
|
||||
|
||||
//// [circularTypeofWithVarOrFunc.js]
|
||||
var varOfAliasedType1;
|
||||
var varOfAliasedType2;
|
||||
function func() { return null; }
|
||||
var varOfAliasedType3 = func();
|
||||
@ -1,15 +1,21 @@
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(4,6): error TS2456: Type alias 'T0' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(5,6): error TS2456: Type alias 'T0_1' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(6,6): error TS2456: Type alias 'T0_2' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(7,6): error TS2456: Type alias 'T0_3' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(11,6): error TS2456: Type alias 'T1' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(14,6): error TS2456: Type alias 'T2' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(16,6): error TS2456: Type alias 'T2_1' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(19,6): error TS2456: Type alias 'T3' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(22,6): error TS2456: Type alias 'T4' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(25,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(26,6): error TS2456: Type alias 'T5' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(29,6): error TS2456: Type alias 'T6' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(30,6): error TS2456: Type alias 'T7' circularly references itself.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(31,5): error TS2502: 'yy' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(32,6): error TS2456: Type alias 'T8' circularly references itself.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts (9 errors) ====
|
||||
==== tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts (15 errors) ====
|
||||
// It is an error for the type specified in a type alias to depend on that type alias
|
||||
|
||||
// A type alias directly depends on the type it aliases.
|
||||
@ -17,10 +23,14 @@ tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(
|
||||
~~
|
||||
!!! error TS2456: Type alias 'T0' circularly references itself.
|
||||
type T0_1 = T0_2
|
||||
~~~~
|
||||
!!! error TS2456: Type alias 'T0_1' circularly references itself.
|
||||
type T0_2 = T0_3
|
||||
~~~~
|
||||
!!! error TS2456: Type alias 'T0_2' circularly references itself.
|
||||
type T0_3 = T0_1
|
||||
~~~~
|
||||
!!! error TS2456: Type alias 'T0_3' circularly references itself.
|
||||
|
||||
// A type reference directly depends on the referenced type and each of the type arguments, if any.
|
||||
interface I<T> {}
|
||||
@ -49,17 +59,25 @@ tests/cases/conformance/types/typeAliases/directDependenceBetweenTypeAliases.ts(
|
||||
|
||||
// A type query directly depends on the type of the referenced entity.
|
||||
var x: T5[] = []
|
||||
~
|
||||
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
|
||||
type T5 = typeof x
|
||||
~~
|
||||
!!! error TS2456: Type alias 'T5' circularly references itself.
|
||||
|
||||
class C1<T> {}
|
||||
type T6 = T7 | number
|
||||
~~
|
||||
!!! error TS2456: Type alias 'T6' circularly references itself.
|
||||
type T7 = typeof yy
|
||||
~~
|
||||
!!! error TS2456: Type alias 'T7' circularly references itself.
|
||||
var yy: [string, T8[]];
|
||||
~~
|
||||
!!! error TS2502: 'yy' is referenced directly or indirectly in its own type annotation.
|
||||
type T8 = C<T6>
|
||||
~~
|
||||
!!! error TS2456: Type alias 'T8' circularly references itself.
|
||||
|
||||
// legal cases
|
||||
type T9 = () => T9
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of33.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of33.ts(4,5): error TS7023: '[Symbol.iterator]' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of33.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of33.ts (2 errors) ====
|
||||
for (var v of new StringIterator) { }
|
||||
~
|
||||
!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
|
||||
class StringIterator {
|
||||
[Symbol.iterator]() {
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS7023: '[Symbol.iterator]' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
return v;
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,16 @@
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of34.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of34.ts(4,5): error TS7023: 'next' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of34.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of34.ts (2 errors) ====
|
||||
for (var v of new StringIterator) { }
|
||||
~
|
||||
!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
~~~~
|
||||
!!! error TS7023: 'next' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of35.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of35.ts(4,5): error TS7023: 'next' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of35.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of35.ts (2 errors) ====
|
||||
for (var v of new StringIterator) { }
|
||||
~
|
||||
!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
~~~~
|
||||
!!! error TS7023: 'next' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
return {
|
||||
done: true,
|
||||
value: v
|
||||
|
||||
@ -1,31 +1,35 @@
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(3,5): error TS7021: 'a' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(7,5): error TS7021: 'c' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(10,5): error TS7021: 'd' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(3,5): error TS2502: 'a' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(6,5): error TS2502: 'b' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(7,5): error TS2502: 'c' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(10,5): error TS2502: 'd' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(15,10): error TS7023: 'g' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(18,10): error TS7024: Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(23,10): error TS7024: Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(26,10): error TS7023: 'h' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(28,14): error TS7023: 'foo' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(41,5): error TS7022: 's' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
|
||||
tests/cases/compiler/implicitAnyFromCircularInference.ts(46,5): error TS7023: 'x' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
|
||||
|
||||
==== tests/cases/compiler/implicitAnyFromCircularInference.ts (9 errors) ====
|
||||
==== tests/cases/compiler/implicitAnyFromCircularInference.ts (11 errors) ====
|
||||
|
||||
// Error expected
|
||||
var a: typeof a;
|
||||
~
|
||||
!!! error TS7021: 'a' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.
|
||||
!!! error TS2502: 'a' is referenced directly or indirectly in its own type annotation.
|
||||
|
||||
// Error expected on b or c
|
||||
var b: typeof c;
|
||||
~
|
||||
!!! error TS2502: 'b' is referenced directly or indirectly in its own type annotation.
|
||||
var c: typeof b;
|
||||
~
|
||||
!!! error TS7021: 'c' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.
|
||||
!!! error TS2502: 'c' is referenced directly or indirectly in its own type annotation.
|
||||
|
||||
// Error expected
|
||||
var d: Array<typeof d>;
|
||||
~
|
||||
!!! error TS7021: 'd' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.
|
||||
!!! error TS2502: 'd' is referenced directly or indirectly in its own type annotation.
|
||||
|
||||
function f() { return f; }
|
||||
|
||||
@ -52,6 +56,8 @@ tests/cases/compiler/implicitAnyFromCircularInference.ts(46,5): error TS7023: 'x
|
||||
!!! error TS7023: 'h' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
return foo();
|
||||
function foo() {
|
||||
~~~
|
||||
!!! error TS7023: 'foo' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
|
||||
return h() || "hello";
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,76 @@
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts(2,5): error TS2502: 'c' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts(4,5): error TS2502: 'd' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts(6,5): error TS2502: 'e' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts(10,5): error TS2502: 'f' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts(12,5): error TS2502: 'f2' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts(14,5): error TS2502: 'f3' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts(51,5): error TS2502: 'hy3' is referenced directly or indirectly in its own type annotation.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts (7 errors) ====
|
||||
// The following are errors because of circular references
|
||||
var c: typeof c;
|
||||
~
|
||||
!!! error TS2502: 'c' is referenced directly or indirectly in its own type annotation.
|
||||
var c: any;
|
||||
var d: typeof e;
|
||||
~
|
||||
!!! error TS2502: 'd' is referenced directly or indirectly in its own type annotation.
|
||||
var d: any;
|
||||
var e: typeof d;
|
||||
~
|
||||
!!! error TS2502: 'e' is referenced directly or indirectly in its own type annotation.
|
||||
var e: any;
|
||||
|
||||
interface Foo<T> { }
|
||||
var f: Array<typeof f>;
|
||||
~
|
||||
!!! error TS2502: 'f' is referenced directly or indirectly in its own type annotation.
|
||||
var f: any;
|
||||
var f2: Foo<typeof f2>;
|
||||
~~
|
||||
!!! error TS2502: 'f2' is referenced directly or indirectly in its own type annotation.
|
||||
var f2: any;
|
||||
var f3: Foo<typeof f3>[];
|
||||
~~
|
||||
!!! error TS2502: 'f3' is referenced directly or indirectly in its own type annotation.
|
||||
var f3: any;
|
||||
|
||||
// None of these declarations should have any errors!
|
||||
// Truly recursive types
|
||||
var g: { x: typeof g; };
|
||||
var g: typeof g.x;
|
||||
var h: () => typeof h;
|
||||
var h = h();
|
||||
var i: (x: typeof i) => typeof x;
|
||||
var i = i(i);
|
||||
var j: <T extends typeof j>(x: T) => T;
|
||||
var j = j(j);
|
||||
|
||||
// Same as h, i, j with construct signatures
|
||||
var h2: new () => typeof h2;
|
||||
var h2 = new h2();
|
||||
var i2: new (x: typeof i2) => typeof x;
|
||||
var i2 = new i2(i2);
|
||||
var j2: new <T extends typeof j2>(x: T) => T;
|
||||
var j2 = new j2(j2);
|
||||
|
||||
// Indexers
|
||||
var k: { [n: number]: typeof k;[s: string]: typeof k };
|
||||
var k = k[0];
|
||||
var k = k[''];
|
||||
|
||||
// Hybrid - contains type literals as well as type arguments
|
||||
// These two are recursive
|
||||
var hy1: { x: typeof hy1 }[];
|
||||
var hy1 = hy1[0].x;
|
||||
var hy2: { x: Array<typeof hy2> };
|
||||
var hy2 = hy2.x[0];
|
||||
|
||||
interface Foo2<T, U> { }
|
||||
|
||||
// This one should be an error because the first type argument is not contained inside a type literal
|
||||
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
|
||||
~~~
|
||||
!!! error TS2502: 'hy3' is referenced directly or indirectly in its own type annotation.
|
||||
var hy3: any;
|
||||
@ -1,6 +1,5 @@
|
||||
//// [recursiveTypesWithTypeof.ts]
|
||||
// None of these declarations should have any errors!
|
||||
// Using typeof directly, these should be any
|
||||
// The following are errors because of circular references
|
||||
var c: typeof c;
|
||||
var c: any;
|
||||
var d: typeof e;
|
||||
@ -8,7 +7,6 @@ var d: any;
|
||||
var e: typeof d;
|
||||
var e: any;
|
||||
|
||||
// In type arguments, these should be any
|
||||
interface Foo<T> { }
|
||||
var f: Array<typeof f>;
|
||||
var f: any;
|
||||
@ -17,6 +15,7 @@ var f2: any;
|
||||
var f3: Foo<typeof f3>[];
|
||||
var f3: any;
|
||||
|
||||
// None of these declarations should have any errors!
|
||||
// Truly recursive types
|
||||
var g: { x: typeof g; };
|
||||
var g: typeof g.x;
|
||||
@ -49,25 +48,25 @@ var hy2 = hy2.x[0];
|
||||
|
||||
interface Foo2<T, U> { }
|
||||
|
||||
// This one should be any because the first type argument is not contained inside a type literal
|
||||
// This one should be an error because the first type argument is not contained inside a type literal
|
||||
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
|
||||
var hy3: any;
|
||||
|
||||
//// [recursiveTypesWithTypeof.js]
|
||||
// The following are errors because of circular references
|
||||
var c;
|
||||
var c;
|
||||
var d;
|
||||
var d;
|
||||
var e;
|
||||
var e;
|
||||
var f;
|
||||
var f;
|
||||
var f2;
|
||||
var f2;
|
||||
var f3;
|
||||
var f3;
|
||||
// None of these declarations should have any errors!
|
||||
// Using typeof directly, these should be any
|
||||
var c;
|
||||
var c;
|
||||
var d;
|
||||
var d;
|
||||
var e;
|
||||
var e;
|
||||
var f;
|
||||
var f;
|
||||
var f2;
|
||||
var f2;
|
||||
var f3;
|
||||
var f3;
|
||||
// Truly recursive types
|
||||
var g;
|
||||
var g;
|
||||
@ -94,6 +93,6 @@ var hy1;
|
||||
var hy1 = hy1[0].x;
|
||||
var hy2;
|
||||
var hy2 = hy2.x[0];
|
||||
// This one should be any because the first type argument is not contained inside a type literal
|
||||
// This one should be an error because the first type argument is not contained inside a type literal
|
||||
var hy3;
|
||||
var hy3;
|
||||
|
||||
@ -1,187 +0,0 @@
|
||||
=== tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts ===
|
||||
// None of these declarations should have any errors!
|
||||
// Using typeof directly, these should be any
|
||||
var c: typeof c;
|
||||
>c : Symbol(c, Decl(recursiveTypesWithTypeof.ts, 2, 3), Decl(recursiveTypesWithTypeof.ts, 3, 3))
|
||||
>c : Symbol(c, Decl(recursiveTypesWithTypeof.ts, 2, 3), Decl(recursiveTypesWithTypeof.ts, 3, 3))
|
||||
|
||||
var c: any;
|
||||
>c : Symbol(c, Decl(recursiveTypesWithTypeof.ts, 2, 3), Decl(recursiveTypesWithTypeof.ts, 3, 3))
|
||||
|
||||
var d: typeof e;
|
||||
>d : Symbol(d, Decl(recursiveTypesWithTypeof.ts, 4, 3), Decl(recursiveTypesWithTypeof.ts, 5, 3))
|
||||
>e : Symbol(e, Decl(recursiveTypesWithTypeof.ts, 6, 3), Decl(recursiveTypesWithTypeof.ts, 7, 3))
|
||||
|
||||
var d: any;
|
||||
>d : Symbol(d, Decl(recursiveTypesWithTypeof.ts, 4, 3), Decl(recursiveTypesWithTypeof.ts, 5, 3))
|
||||
|
||||
var e: typeof d;
|
||||
>e : Symbol(e, Decl(recursiveTypesWithTypeof.ts, 6, 3), Decl(recursiveTypesWithTypeof.ts, 7, 3))
|
||||
>d : Symbol(d, Decl(recursiveTypesWithTypeof.ts, 4, 3), Decl(recursiveTypesWithTypeof.ts, 5, 3))
|
||||
|
||||
var e: any;
|
||||
>e : Symbol(e, Decl(recursiveTypesWithTypeof.ts, 6, 3), Decl(recursiveTypesWithTypeof.ts, 7, 3))
|
||||
|
||||
// In type arguments, these should be any
|
||||
interface Foo<T> { }
|
||||
>Foo : Symbol(Foo, Decl(recursiveTypesWithTypeof.ts, 7, 11))
|
||||
>T : Symbol(T, Decl(recursiveTypesWithTypeof.ts, 10, 14))
|
||||
|
||||
var f: Array<typeof f>;
|
||||
>f : Symbol(f, Decl(recursiveTypesWithTypeof.ts, 11, 3), Decl(recursiveTypesWithTypeof.ts, 12, 3))
|
||||
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
|
||||
>f : Symbol(f, Decl(recursiveTypesWithTypeof.ts, 11, 3), Decl(recursiveTypesWithTypeof.ts, 12, 3))
|
||||
|
||||
var f: any;
|
||||
>f : Symbol(f, Decl(recursiveTypesWithTypeof.ts, 11, 3), Decl(recursiveTypesWithTypeof.ts, 12, 3))
|
||||
|
||||
var f2: Foo<typeof f2>;
|
||||
>f2 : Symbol(f2, Decl(recursiveTypesWithTypeof.ts, 13, 3), Decl(recursiveTypesWithTypeof.ts, 14, 3))
|
||||
>Foo : Symbol(Foo, Decl(recursiveTypesWithTypeof.ts, 7, 11))
|
||||
>f2 : Symbol(f2, Decl(recursiveTypesWithTypeof.ts, 13, 3), Decl(recursiveTypesWithTypeof.ts, 14, 3))
|
||||
|
||||
var f2: any;
|
||||
>f2 : Symbol(f2, Decl(recursiveTypesWithTypeof.ts, 13, 3), Decl(recursiveTypesWithTypeof.ts, 14, 3))
|
||||
|
||||
var f3: Foo<typeof f3>[];
|
||||
>f3 : Symbol(f3, Decl(recursiveTypesWithTypeof.ts, 15, 3), Decl(recursiveTypesWithTypeof.ts, 16, 3))
|
||||
>Foo : Symbol(Foo, Decl(recursiveTypesWithTypeof.ts, 7, 11))
|
||||
>f3 : Symbol(f3, Decl(recursiveTypesWithTypeof.ts, 15, 3), Decl(recursiveTypesWithTypeof.ts, 16, 3))
|
||||
|
||||
var f3: any;
|
||||
>f3 : Symbol(f3, Decl(recursiveTypesWithTypeof.ts, 15, 3), Decl(recursiveTypesWithTypeof.ts, 16, 3))
|
||||
|
||||
// Truly recursive types
|
||||
var g: { x: typeof g; };
|
||||
>g : Symbol(g, Decl(recursiveTypesWithTypeof.ts, 19, 3), Decl(recursiveTypesWithTypeof.ts, 20, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 19, 8))
|
||||
>g : Symbol(g, Decl(recursiveTypesWithTypeof.ts, 19, 3), Decl(recursiveTypesWithTypeof.ts, 20, 3))
|
||||
|
||||
var g: typeof g.x;
|
||||
>g : Symbol(g, Decl(recursiveTypesWithTypeof.ts, 19, 3), Decl(recursiveTypesWithTypeof.ts, 20, 3))
|
||||
>g.x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 19, 8))
|
||||
>g : Symbol(g, Decl(recursiveTypesWithTypeof.ts, 19, 3), Decl(recursiveTypesWithTypeof.ts, 20, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 19, 8))
|
||||
|
||||
var h: () => typeof h;
|
||||
>h : Symbol(h, Decl(recursiveTypesWithTypeof.ts, 21, 3), Decl(recursiveTypesWithTypeof.ts, 22, 3))
|
||||
>h : Symbol(h, Decl(recursiveTypesWithTypeof.ts, 21, 3), Decl(recursiveTypesWithTypeof.ts, 22, 3))
|
||||
|
||||
var h = h();
|
||||
>h : Symbol(h, Decl(recursiveTypesWithTypeof.ts, 21, 3), Decl(recursiveTypesWithTypeof.ts, 22, 3))
|
||||
>h : Symbol(h, Decl(recursiveTypesWithTypeof.ts, 21, 3), Decl(recursiveTypesWithTypeof.ts, 22, 3))
|
||||
|
||||
var i: (x: typeof i) => typeof x;
|
||||
>i : Symbol(i, Decl(recursiveTypesWithTypeof.ts, 23, 3), Decl(recursiveTypesWithTypeof.ts, 24, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 23, 8))
|
||||
>i : Symbol(i, Decl(recursiveTypesWithTypeof.ts, 23, 3), Decl(recursiveTypesWithTypeof.ts, 24, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 23, 8))
|
||||
|
||||
var i = i(i);
|
||||
>i : Symbol(i, Decl(recursiveTypesWithTypeof.ts, 23, 3), Decl(recursiveTypesWithTypeof.ts, 24, 3))
|
||||
>i : Symbol(i, Decl(recursiveTypesWithTypeof.ts, 23, 3), Decl(recursiveTypesWithTypeof.ts, 24, 3))
|
||||
>i : Symbol(i, Decl(recursiveTypesWithTypeof.ts, 23, 3), Decl(recursiveTypesWithTypeof.ts, 24, 3))
|
||||
|
||||
var j: <T extends typeof j>(x: T) => T;
|
||||
>j : Symbol(j, Decl(recursiveTypesWithTypeof.ts, 25, 3), Decl(recursiveTypesWithTypeof.ts, 26, 3))
|
||||
>T : Symbol(T, Decl(recursiveTypesWithTypeof.ts, 25, 8))
|
||||
>j : Symbol(j, Decl(recursiveTypesWithTypeof.ts, 25, 3), Decl(recursiveTypesWithTypeof.ts, 26, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 25, 28))
|
||||
>T : Symbol(T, Decl(recursiveTypesWithTypeof.ts, 25, 8))
|
||||
>T : Symbol(T, Decl(recursiveTypesWithTypeof.ts, 25, 8))
|
||||
|
||||
var j = j(j);
|
||||
>j : Symbol(j, Decl(recursiveTypesWithTypeof.ts, 25, 3), Decl(recursiveTypesWithTypeof.ts, 26, 3))
|
||||
>j : Symbol(j, Decl(recursiveTypesWithTypeof.ts, 25, 3), Decl(recursiveTypesWithTypeof.ts, 26, 3))
|
||||
>j : Symbol(j, Decl(recursiveTypesWithTypeof.ts, 25, 3), Decl(recursiveTypesWithTypeof.ts, 26, 3))
|
||||
|
||||
// Same as h, i, j with construct signatures
|
||||
var h2: new () => typeof h2;
|
||||
>h2 : Symbol(h2, Decl(recursiveTypesWithTypeof.ts, 29, 3), Decl(recursiveTypesWithTypeof.ts, 30, 3))
|
||||
>h2 : Symbol(h2, Decl(recursiveTypesWithTypeof.ts, 29, 3), Decl(recursiveTypesWithTypeof.ts, 30, 3))
|
||||
|
||||
var h2 = new h2();
|
||||
>h2 : Symbol(h2, Decl(recursiveTypesWithTypeof.ts, 29, 3), Decl(recursiveTypesWithTypeof.ts, 30, 3))
|
||||
>h2 : Symbol(h2, Decl(recursiveTypesWithTypeof.ts, 29, 3), Decl(recursiveTypesWithTypeof.ts, 30, 3))
|
||||
|
||||
var i2: new (x: typeof i2) => typeof x;
|
||||
>i2 : Symbol(i2, Decl(recursiveTypesWithTypeof.ts, 31, 3), Decl(recursiveTypesWithTypeof.ts, 32, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 31, 13))
|
||||
>i2 : Symbol(i2, Decl(recursiveTypesWithTypeof.ts, 31, 3), Decl(recursiveTypesWithTypeof.ts, 32, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 31, 13))
|
||||
|
||||
var i2 = new i2(i2);
|
||||
>i2 : Symbol(i2, Decl(recursiveTypesWithTypeof.ts, 31, 3), Decl(recursiveTypesWithTypeof.ts, 32, 3))
|
||||
>i2 : Symbol(i2, Decl(recursiveTypesWithTypeof.ts, 31, 3), Decl(recursiveTypesWithTypeof.ts, 32, 3))
|
||||
>i2 : Symbol(i2, Decl(recursiveTypesWithTypeof.ts, 31, 3), Decl(recursiveTypesWithTypeof.ts, 32, 3))
|
||||
|
||||
var j2: new <T extends typeof j2>(x: T) => T;
|
||||
>j2 : Symbol(j2, Decl(recursiveTypesWithTypeof.ts, 33, 3), Decl(recursiveTypesWithTypeof.ts, 34, 3))
|
||||
>T : Symbol(T, Decl(recursiveTypesWithTypeof.ts, 33, 13))
|
||||
>j2 : Symbol(j2, Decl(recursiveTypesWithTypeof.ts, 33, 3), Decl(recursiveTypesWithTypeof.ts, 34, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 33, 34))
|
||||
>T : Symbol(T, Decl(recursiveTypesWithTypeof.ts, 33, 13))
|
||||
>T : Symbol(T, Decl(recursiveTypesWithTypeof.ts, 33, 13))
|
||||
|
||||
var j2 = new j2(j2);
|
||||
>j2 : Symbol(j2, Decl(recursiveTypesWithTypeof.ts, 33, 3), Decl(recursiveTypesWithTypeof.ts, 34, 3))
|
||||
>j2 : Symbol(j2, Decl(recursiveTypesWithTypeof.ts, 33, 3), Decl(recursiveTypesWithTypeof.ts, 34, 3))
|
||||
>j2 : Symbol(j2, Decl(recursiveTypesWithTypeof.ts, 33, 3), Decl(recursiveTypesWithTypeof.ts, 34, 3))
|
||||
|
||||
// Indexers
|
||||
var k: { [n: number]: typeof k;[s: string]: typeof k };
|
||||
>k : Symbol(k, Decl(recursiveTypesWithTypeof.ts, 37, 3), Decl(recursiveTypesWithTypeof.ts, 38, 3), Decl(recursiveTypesWithTypeof.ts, 39, 3))
|
||||
>n : Symbol(n, Decl(recursiveTypesWithTypeof.ts, 37, 10))
|
||||
>k : Symbol(k, Decl(recursiveTypesWithTypeof.ts, 37, 3), Decl(recursiveTypesWithTypeof.ts, 38, 3), Decl(recursiveTypesWithTypeof.ts, 39, 3))
|
||||
>s : Symbol(s, Decl(recursiveTypesWithTypeof.ts, 37, 32))
|
||||
>k : Symbol(k, Decl(recursiveTypesWithTypeof.ts, 37, 3), Decl(recursiveTypesWithTypeof.ts, 38, 3), Decl(recursiveTypesWithTypeof.ts, 39, 3))
|
||||
|
||||
var k = k[0];
|
||||
>k : Symbol(k, Decl(recursiveTypesWithTypeof.ts, 37, 3), Decl(recursiveTypesWithTypeof.ts, 38, 3), Decl(recursiveTypesWithTypeof.ts, 39, 3))
|
||||
>k : Symbol(k, Decl(recursiveTypesWithTypeof.ts, 37, 3), Decl(recursiveTypesWithTypeof.ts, 38, 3), Decl(recursiveTypesWithTypeof.ts, 39, 3))
|
||||
|
||||
var k = k[''];
|
||||
>k : Symbol(k, Decl(recursiveTypesWithTypeof.ts, 37, 3), Decl(recursiveTypesWithTypeof.ts, 38, 3), Decl(recursiveTypesWithTypeof.ts, 39, 3))
|
||||
>k : Symbol(k, Decl(recursiveTypesWithTypeof.ts, 37, 3), Decl(recursiveTypesWithTypeof.ts, 38, 3), Decl(recursiveTypesWithTypeof.ts, 39, 3))
|
||||
|
||||
// Hybrid - contains type literals as well as type arguments
|
||||
// These two are recursive
|
||||
var hy1: { x: typeof hy1 }[];
|
||||
>hy1 : Symbol(hy1, Decl(recursiveTypesWithTypeof.ts, 43, 3), Decl(recursiveTypesWithTypeof.ts, 44, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 43, 10))
|
||||
>hy1 : Symbol(hy1, Decl(recursiveTypesWithTypeof.ts, 43, 3), Decl(recursiveTypesWithTypeof.ts, 44, 3))
|
||||
|
||||
var hy1 = hy1[0].x;
|
||||
>hy1 : Symbol(hy1, Decl(recursiveTypesWithTypeof.ts, 43, 3), Decl(recursiveTypesWithTypeof.ts, 44, 3))
|
||||
>hy1[0].x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 43, 10))
|
||||
>hy1 : Symbol(hy1, Decl(recursiveTypesWithTypeof.ts, 43, 3), Decl(recursiveTypesWithTypeof.ts, 44, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 43, 10))
|
||||
|
||||
var hy2: { x: Array<typeof hy2> };
|
||||
>hy2 : Symbol(hy2, Decl(recursiveTypesWithTypeof.ts, 45, 3), Decl(recursiveTypesWithTypeof.ts, 46, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 45, 10))
|
||||
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
|
||||
>hy2 : Symbol(hy2, Decl(recursiveTypesWithTypeof.ts, 45, 3), Decl(recursiveTypesWithTypeof.ts, 46, 3))
|
||||
|
||||
var hy2 = hy2.x[0];
|
||||
>hy2 : Symbol(hy2, Decl(recursiveTypesWithTypeof.ts, 45, 3), Decl(recursiveTypesWithTypeof.ts, 46, 3))
|
||||
>hy2.x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 45, 10))
|
||||
>hy2 : Symbol(hy2, Decl(recursiveTypesWithTypeof.ts, 45, 3), Decl(recursiveTypesWithTypeof.ts, 46, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 45, 10))
|
||||
|
||||
interface Foo2<T, U> { }
|
||||
>Foo2 : Symbol(Foo2, Decl(recursiveTypesWithTypeof.ts, 46, 19))
|
||||
>T : Symbol(T, Decl(recursiveTypesWithTypeof.ts, 48, 15))
|
||||
>U : Symbol(U, Decl(recursiveTypesWithTypeof.ts, 48, 17))
|
||||
|
||||
// This one should be any because the first type argument is not contained inside a type literal
|
||||
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
|
||||
>hy3 : Symbol(hy3, Decl(recursiveTypesWithTypeof.ts, 51, 3), Decl(recursiveTypesWithTypeof.ts, 52, 3))
|
||||
>Foo2 : Symbol(Foo2, Decl(recursiveTypesWithTypeof.ts, 46, 19))
|
||||
>hy3 : Symbol(hy3, Decl(recursiveTypesWithTypeof.ts, 51, 3), Decl(recursiveTypesWithTypeof.ts, 52, 3))
|
||||
>x : Symbol(x, Decl(recursiveTypesWithTypeof.ts, 51, 27))
|
||||
>hy3 : Symbol(hy3, Decl(recursiveTypesWithTypeof.ts, 51, 3), Decl(recursiveTypesWithTypeof.ts, 52, 3))
|
||||
|
||||
var hy3: any;
|
||||
>hy3 : Symbol(hy3, Decl(recursiveTypesWithTypeof.ts, 51, 3), Decl(recursiveTypesWithTypeof.ts, 52, 3))
|
||||
|
||||
@ -1,201 +0,0 @@
|
||||
=== tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts ===
|
||||
// None of these declarations should have any errors!
|
||||
// Using typeof directly, these should be any
|
||||
var c: typeof c;
|
||||
>c : any
|
||||
>c : any
|
||||
|
||||
var c: any;
|
||||
>c : any
|
||||
|
||||
var d: typeof e;
|
||||
>d : any
|
||||
>e : any
|
||||
|
||||
var d: any;
|
||||
>d : any
|
||||
|
||||
var e: typeof d;
|
||||
>e : any
|
||||
>d : any
|
||||
|
||||
var e: any;
|
||||
>e : any
|
||||
|
||||
// In type arguments, these should be any
|
||||
interface Foo<T> { }
|
||||
>Foo : Foo<T>
|
||||
>T : T
|
||||
|
||||
var f: Array<typeof f>;
|
||||
>f : any
|
||||
>Array : T[]
|
||||
>f : any
|
||||
|
||||
var f: any;
|
||||
>f : any
|
||||
|
||||
var f2: Foo<typeof f2>;
|
||||
>f2 : any
|
||||
>Foo : Foo<T>
|
||||
>f2 : any
|
||||
|
||||
var f2: any;
|
||||
>f2 : any
|
||||
|
||||
var f3: Foo<typeof f3>[];
|
||||
>f3 : any
|
||||
>Foo : Foo<T>
|
||||
>f3 : any
|
||||
|
||||
var f3: any;
|
||||
>f3 : any
|
||||
|
||||
// Truly recursive types
|
||||
var g: { x: typeof g; };
|
||||
>g : { x: any; }
|
||||
>x : { x: any; }
|
||||
>g : { x: any; }
|
||||
|
||||
var g: typeof g.x;
|
||||
>g : { x: any; }
|
||||
>g.x : { x: any; }
|
||||
>g : { x: any; }
|
||||
>x : { x: any; }
|
||||
|
||||
var h: () => typeof h;
|
||||
>h : () => any
|
||||
>h : () => any
|
||||
|
||||
var h = h();
|
||||
>h : () => any
|
||||
>h() : () => any
|
||||
>h : () => any
|
||||
|
||||
var i: (x: typeof i) => typeof x;
|
||||
>i : (x: any) => any
|
||||
>x : (x: any) => any
|
||||
>i : (x: any) => any
|
||||
>x : (x: any) => any
|
||||
|
||||
var i = i(i);
|
||||
>i : (x: any) => any
|
||||
>i(i) : (x: any) => any
|
||||
>i : (x: any) => any
|
||||
>i : (x: any) => any
|
||||
|
||||
var j: <T extends typeof j>(x: T) => T;
|
||||
>j : <T extends any>(x: T) => T
|
||||
>T : T
|
||||
>j : <T extends any>(x: T) => T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
var j = j(j);
|
||||
>j : <T extends any>(x: T) => T
|
||||
>j(j) : <T extends any>(x: T) => T
|
||||
>j : <T extends any>(x: T) => T
|
||||
>j : <T extends any>(x: T) => T
|
||||
|
||||
// Same as h, i, j with construct signatures
|
||||
var h2: new () => typeof h2;
|
||||
>h2 : new () => any
|
||||
>h2 : new () => any
|
||||
|
||||
var h2 = new h2();
|
||||
>h2 : new () => any
|
||||
>new h2() : new () => any
|
||||
>h2 : new () => any
|
||||
|
||||
var i2: new (x: typeof i2) => typeof x;
|
||||
>i2 : new (x: any) => any
|
||||
>x : new (x: any) => any
|
||||
>i2 : new (x: any) => any
|
||||
>x : new (x: any) => any
|
||||
|
||||
var i2 = new i2(i2);
|
||||
>i2 : new (x: any) => any
|
||||
>new i2(i2) : new (x: any) => any
|
||||
>i2 : new (x: any) => any
|
||||
>i2 : new (x: any) => any
|
||||
|
||||
var j2: new <T extends typeof j2>(x: T) => T;
|
||||
>j2 : new <T extends any>(x: T) => T
|
||||
>T : T
|
||||
>j2 : new <T extends any>(x: T) => T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
var j2 = new j2(j2);
|
||||
>j2 : new <T extends any>(x: T) => T
|
||||
>new j2(j2) : new <T extends any>(x: T) => T
|
||||
>j2 : new <T extends any>(x: T) => T
|
||||
>j2 : new <T extends any>(x: T) => T
|
||||
|
||||
// Indexers
|
||||
var k: { [n: number]: typeof k;[s: string]: typeof k };
|
||||
>k : { [s: string]: any; [n: number]: any; }
|
||||
>n : number
|
||||
>k : { [s: string]: any; [n: number]: any; }
|
||||
>s : string
|
||||
>k : { [s: string]: any; [n: number]: any; }
|
||||
|
||||
var k = k[0];
|
||||
>k : { [s: string]: any; [n: number]: any; }
|
||||
>k[0] : { [s: string]: any; [n: number]: any; }
|
||||
>k : { [s: string]: any; [n: number]: any; }
|
||||
>0 : number
|
||||
|
||||
var k = k[''];
|
||||
>k : { [s: string]: any; [n: number]: any; }
|
||||
>k[''] : { [s: string]: any; [n: number]: any; }
|
||||
>k : { [s: string]: any; [n: number]: any; }
|
||||
>'' : string
|
||||
|
||||
// Hybrid - contains type literals as well as type arguments
|
||||
// These two are recursive
|
||||
var hy1: { x: typeof hy1 }[];
|
||||
>hy1 : { x: any[]; }[]
|
||||
>x : { x: any[]; }[]
|
||||
>hy1 : { x: any[]; }[]
|
||||
|
||||
var hy1 = hy1[0].x;
|
||||
>hy1 : { x: any[]; }[]
|
||||
>hy1[0].x : { x: any[]; }[]
|
||||
>hy1[0] : { x: any[]; }
|
||||
>hy1 : { x: any[]; }[]
|
||||
>0 : number
|
||||
>x : { x: any[]; }[]
|
||||
|
||||
var hy2: { x: Array<typeof hy2> };
|
||||
>hy2 : { x: any[]; }
|
||||
>x : { x: any[]; }[]
|
||||
>Array : T[]
|
||||
>hy2 : { x: any[]; }
|
||||
|
||||
var hy2 = hy2.x[0];
|
||||
>hy2 : { x: any[]; }
|
||||
>hy2.x[0] : { x: any[]; }
|
||||
>hy2.x : { x: any[]; }[]
|
||||
>hy2 : { x: any[]; }
|
||||
>x : { x: any[]; }[]
|
||||
>0 : number
|
||||
|
||||
interface Foo2<T, U> { }
|
||||
>Foo2 : Foo2<T, U>
|
||||
>T : T
|
||||
>U : U
|
||||
|
||||
// This one should be any because the first type argument is not contained inside a type literal
|
||||
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
|
||||
>hy3 : any
|
||||
>Foo2 : Foo2<T, U>
|
||||
>hy3 : any
|
||||
>x : any
|
||||
>hy3 : any
|
||||
|
||||
var hy3: any;
|
||||
>hy3 : any
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofANonExportedType.ts(2,1): error TS1148: Cannot compile modules unless the '--module' flag is provided.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofANonExportedType.ts(42,12): error TS2502: 'r12' is referenced directly or indirectly in its own type annotation.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/specifyingTypes/typeQueries/typeofANonExportedType.ts (1 errors) ====
|
||||
==== tests/cases/conformance/types/specifyingTypes/typeQueries/typeofANonExportedType.ts (2 errors) ====
|
||||
var x = 1;
|
||||
export var r1: typeof x;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@ -46,6 +47,8 @@ tests/cases/conformance/types/specifyingTypes/typeQueries/typeofANonExportedType
|
||||
export var r11: typeof E.A;
|
||||
|
||||
export var r12: typeof r12;
|
||||
~~~
|
||||
!!! error TS2502: 'r12' is referenced directly or indirectly in its own type annotation.
|
||||
|
||||
function foo() { }
|
||||
module foo {
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofAnExportedType.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided.
|
||||
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofAnExportedType.ts(42,12): error TS2502: 'r12' is referenced directly or indirectly in its own type annotation.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/specifyingTypes/typeQueries/typeofAnExportedType.ts (1 errors) ====
|
||||
==== tests/cases/conformance/types/specifyingTypes/typeQueries/typeofAnExportedType.ts (2 errors) ====
|
||||
export var x = 1;
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided.
|
||||
@ -46,6 +47,8 @@ tests/cases/conformance/types/specifyingTypes/typeQueries/typeofAnExportedType.t
|
||||
export var r11: typeof E.A;
|
||||
|
||||
export var r12: typeof r12;
|
||||
~~~
|
||||
!!! error TS2502: 'r12' is referenced directly or indirectly in its own type annotation.
|
||||
|
||||
export function foo() { }
|
||||
export module foo {
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
type typeAlias1 = typeof varOfAliasedType1;
|
||||
var varOfAliasedType1: typeAlias1;
|
||||
|
||||
var varOfAliasedType2: typeAlias2;
|
||||
type typeAlias2 = typeof varOfAliasedType2;
|
||||
|
||||
function func(): typeAlias3 { return null; }
|
||||
var varOfAliasedType3 = func();
|
||||
type typeAlias3 = typeof varOfAliasedType3;
|
||||
@ -1,5 +1,4 @@
|
||||
// None of these declarations should have any errors!
|
||||
// Using typeof directly, these should be any
|
||||
// The following are errors because of circular references
|
||||
var c: typeof c;
|
||||
var c: any;
|
||||
var d: typeof e;
|
||||
@ -7,7 +6,6 @@ var d: any;
|
||||
var e: typeof d;
|
||||
var e: any;
|
||||
|
||||
// In type arguments, these should be any
|
||||
interface Foo<T> { }
|
||||
var f: Array<typeof f>;
|
||||
var f: any;
|
||||
@ -16,6 +14,7 @@ var f2: any;
|
||||
var f3: Foo<typeof f3>[];
|
||||
var f3: any;
|
||||
|
||||
// None of these declarations should have any errors!
|
||||
// Truly recursive types
|
||||
var g: { x: typeof g; };
|
||||
var g: typeof g.x;
|
||||
@ -48,6 +47,6 @@ var hy2 = hy2.x[0];
|
||||
|
||||
interface Foo2<T, U> { }
|
||||
|
||||
// This one should be any because the first type argument is not contained inside a type literal
|
||||
// This one should be an error because the first type argument is not contained inside a type literal
|
||||
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
|
||||
var hy3: any;
|
||||
Loading…
x
Reference in New Issue
Block a user