diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e15b57fbc2d..ff8a80d370d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3360,8 +3360,13 @@ namespace ts { writeAnonymousType(type, nextFlags); } else if (type.flags & TypeFlags.UniqueESSymbol) { - writeKeyword(writer, SyntaxKind.UniqueKeyword); - writeSpace(writer); + if (flags & TypeFormatFlags.AllowUniqueESSymbolType) { + writeKeyword(writer, SyntaxKind.UniqueKeyword); + writeSpace(writer); + } + else { + writer.reportInaccessibleUniqueSymbolError(); + } writeKeyword(writer, SyntaxKind.SymbolKeyword); } else if (type.flags & TypeFlags.StringOrNumberLiteral) { @@ -8365,9 +8370,7 @@ namespace ts { } function getESSymbolLikeTypeForNode(node: Node) { - if (isVariableDeclaration(node) ? isConst(node) && isIdentifier(node.name) && isVariableDeclarationInVariableStatement(node) : - isPropertyDeclaration(node) ? hasReadonlyModifier(node) && hasStaticModifier(node) : - isPropertySignature(node) && hasReadonlyModifier(node)) { + if (isValidESSymbolDeclaration(node)) { const symbol = getSymbolOfNode(node); const links = getSymbolLinks(symbol); return links.type || (links.type = createUniqueESSymbolType(symbol)); @@ -17694,9 +17697,6 @@ namespace ts { // the native Promise type later in this function. type = checkAwaitedType(type, /*errorNode*/ func, Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member); } - - // widen 'unique symbol' types when we infer the return type. - type = getWidenedUniqueESSymbolType(type); } else { let types: Type[]; @@ -17728,37 +17728,49 @@ namespace ts { : voidType; // Normal function } } + // Return a union of the return expression types. type = getUnionType(types, /*subtypeReduction*/ true); - - // widen 'unique symbol' types when we infer the return type. - type = getWidenedUniqueESSymbolType(type); - - if (functionFlags & FunctionFlags.Generator) { // AsyncGenerator function or Generator function - type = functionFlags & FunctionFlags.Async - ? createAsyncIterableIteratorType(type) // AsyncGenerator function - : createIterableIteratorType(type); // Generator function - } } if (!contextualSignature) { reportErrorsFromWidening(func, type); } - if (isUnitType(type) && - !(contextualSignature && - isLiteralContextualType( - contextualSignature === getSignatureFromDeclaration(func) ? type : getReturnTypeOfSignature(contextualSignature)))) { - type = getWidenedLiteralType(type); + if (isUnitType(type)) { + let contextualType = !contextualSignature ? undefined : + contextualSignature === getSignatureFromDeclaration(func) ? type : + getReturnTypeOfSignature(contextualSignature); + if (contextualType) { + switch (functionFlags & FunctionFlags.AsyncGenerator) { + case FunctionFlags.AsyncGenerator: + contextualType = getIteratedTypeOfGenerator(contextualType, /*isAsyncGenerator*/ true); + break; + case FunctionFlags.Generator: + contextualType = getIteratedTypeOfGenerator(contextualType, /*isAsyncGenerator*/ false); + break; + case FunctionFlags.Async: + contextualType = getPromisedTypeOfPromise(contextualType); + break; + } + } + type = getWidenedLiteralLikeTypeForContextualType(type, contextualType); } const widenedType = getWidenedType(type); - // From within an async function you can return either a non-promise value or a promise. Any - // Promise/A+ compatible implementation will always assimilate any foreign promise, so the - // return type of the body is awaited type of the body, wrapped in a native Promise type. - return (functionFlags & FunctionFlags.AsyncGenerator) === FunctionFlags.Async - ? createPromiseReturnType(func, widenedType) // Async function - : widenedType; // Generator function, AsyncGenerator function, or normal function + switch (functionFlags & FunctionFlags.AsyncGenerator) { + case FunctionFlags.AsyncGenerator: + return createAsyncIterableIteratorType(widenedType); + case FunctionFlags.Generator: + return createIterableIteratorType(widenedType); + case FunctionFlags.Async: + // From within an async function you can return either a non-promise value or a promise. Any + // Promise/A+ compatible implementation will always assimilate any foreign promise, so the + // return type of the body is awaited type of the body, wrapped in a native Promise type. + return createPromiseType(widenedType); + default: + return widenedType; + } } function checkAndAggregateYieldOperandTypes(func: FunctionLikeDeclaration, checkMode: CheckMode): Type[] { @@ -24627,9 +24639,14 @@ namespace ts { let type = symbol && !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.Signature)) ? getWidenedLiteralType(getTypeOfSymbol(symbol)) : unknownType; + if (type.flags & TypeFlags.UniqueESSymbol && + type.symbol === symbol) { + flags |= TypeFormatFlags.AllowUniqueESSymbolType; + } if (flags & TypeFormatFlags.AddUndefined) { type = getNullableType(type, TypeFlags.Undefined); } + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index a671d107d0b..7912d042c0f 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -190,6 +190,7 @@ namespace ts { const writer = createTextWriter(newLine); writer.trackSymbol = trackSymbol; writer.reportInaccessibleThisError = reportInaccessibleThisError; + writer.reportInaccessibleUniqueSymbolError = reportInaccessibleUniqueSymbolError; writer.reportPrivateInBaseOfClassExpression = reportPrivateInBaseOfClassExpression; writer.writeKeyword = writer.write; writer.writeOperator = writer.write; @@ -322,11 +323,21 @@ namespace ts { } } + function reportInaccessibleUniqueSymbolError() { + if (errorNameNode) { + reportedDeclarationError = true; + emitterDiagnostics.add(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary, + declarationNameToString(errorNameNode), + "unique symbol")); + } + } + function reportInaccessibleThisError() { if (errorNameNode) { reportedDeclarationError = true; - emitterDiagnostics.add(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary, - declarationNameToString(errorNameNode))); + emitterDiagnostics.add(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary, + declarationNameToString(errorNameNode), + "this")); } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6671c8f7119..c98fd856ebe 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1804,7 +1804,7 @@ "category": "Error", "code": 2526 }, - "The inferred type of '{0}' references an inaccessible 'this' type. A type annotation is necessary.": { + "The inferred type of '{0}' references an inaccessible '{1}' type. A type annotation is necessary.": { "category": "Error", "code": 2527 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1e8d3505914..bbb6da48d23 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2857,6 +2857,7 @@ namespace ts { trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void; reportInaccessibleThisError(): void; reportPrivateInBaseOfClassExpression(propertyName: string): void; + reportInaccessibleUniqueSymbolError(): void; } export const enum TypeFormatFlags { @@ -2877,6 +2878,7 @@ namespace ts { InArrayType = 1 << 15, // Writing an array element type UseAliasDefinedOutsideCurrentScope = 1 << 16, // For a `type T = ... ` defined in a different file, write `T` instead of its value, // even though `T` can't be accessed in the current scope. + AllowUniqueESSymbolType = 1 << 17, } export const enum SymbolFormatFlags { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c3b208fde53..4c94220e2f1 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -56,6 +56,7 @@ namespace ts { clear: () => str = "", trackSymbol: noop, reportInaccessibleThisError: noop, + reportInaccessibleUniqueSymbolError: noop, reportPrivateInBaseOfClassExpression: noop, }; } @@ -945,6 +946,12 @@ namespace ts { && node.parent.parent.kind === SyntaxKind.VariableStatement; } + export function isValidESSymbolDeclaration(node: Node) { + return isVariableDeclaration(node) ? isConst(node) && isIdentifier(node.name) && isVariableDeclarationInVariableStatement(node) : + isPropertyDeclaration(node) ? hasReadonlyModifier(node) && hasStaticModifier(node) : + isPropertySignature(node) && hasReadonlyModifier(node); + } + export function introducesArgumentsExoticObject(node: Node) { switch (node.kind) { case SyntaxKind.MethodDeclaration: diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts index 378c73f2f75..3f03180360d 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -246,6 +246,7 @@ namespace ts.codefix { }, reportInaccessibleThisError: () => { typeIsAccessible = false; }, reportPrivateInBaseOfClassExpression: () => { typeIsAccessible = false; }, + reportInaccessibleUniqueSymbolError: () => { typeIsAccessible = false; } }; } writer.clear(); diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 36089f94f73..33d35aea557 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1130,6 +1130,7 @@ namespace ts { clear: resetWriter, trackSymbol: noop, reportInaccessibleThisError: noop, + reportInaccessibleUniqueSymbolError: noop, reportPrivateInBaseOfClassExpression: noop, }; diff --git a/tests/baselines/reference/YieldStarExpression4_es6.types b/tests/baselines/reference/YieldStarExpression4_es6.types index 1d72e6dc506..86b727306d4 100644 --- a/tests/baselines/reference/YieldStarExpression4_es6.types +++ b/tests/baselines/reference/YieldStarExpression4_es6.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/yieldExpressions/YieldStarExpression4_es6.ts === function *g() { ->g : () => IterableIterator +>g : () => IterableIterator yield * []; >yield * [] : any diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 7ab0c59e3d4..7aba78318f4 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1826,6 +1826,7 @@ declare namespace ts { trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void; reportInaccessibleThisError(): void; reportPrivateInBaseOfClassExpression(propertyName: string): void; + reportInaccessibleUniqueSymbolError(): void; } enum TypeFormatFlags { None = 0, @@ -1844,6 +1845,7 @@ declare namespace ts { WriteClassExpressionAsTypeLiteral = 16384, InArrayType = 32768, UseAliasDefinedOutsideCurrentScope = 65536, + AllowUniqueESSymbolType = 131072, } enum SymbolFormatFlags { None = 0, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index fbc88ce6249..f18eb1277fc 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1826,6 +1826,7 @@ declare namespace ts { trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void; reportInaccessibleThisError(): void; reportPrivateInBaseOfClassExpression(propertyName: string): void; + reportInaccessibleUniqueSymbolError(): void; } enum TypeFormatFlags { None = 0, @@ -1844,6 +1845,7 @@ declare namespace ts { WriteClassExpressionAsTypeLiteral = 16384, InArrayType = 32768, UseAliasDefinedOutsideCurrentScope = 65536, + AllowUniqueESSymbolType = 131072, } enum SymbolFormatFlags { None = 0, diff --git a/tests/baselines/reference/asyncImportNestedYield.types b/tests/baselines/reference/asyncImportNestedYield.types index 872e3141500..f7fbfa8f962 100644 --- a/tests/baselines/reference/asyncImportNestedYield.types +++ b/tests/baselines/reference/asyncImportNestedYield.types @@ -1,6 +1,6 @@ === tests/cases/compiler/asyncImportNestedYield.ts === async function* foo() { ->foo : () => AsyncIterableIterator<"foo"> +>foo : () => AsyncIterableIterator import((await import(yield "foo")).default); >import((await import(yield "foo")).default) : Promise diff --git a/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.types b/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.types index c375fb6f455..c6d6fb6758d 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.types +++ b/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.types @@ -23,7 +23,7 @@ class C3 { >C3 : C3 async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield 1; >x : any @@ -50,14 +50,14 @@ class C5 { >C5 : C5 async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -80,7 +80,7 @@ class C7 { >C7 : C7 async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/emitter.asyncGenerators.classMethods.es5.types b/tests/baselines/reference/emitter.asyncGenerators.classMethods.es5.types index e4be9f80d4a..5d636d2400c 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.classMethods.es5.types +++ b/tests/baselines/reference/emitter.asyncGenerators.classMethods.es5.types @@ -23,7 +23,7 @@ class C3 { >C3 : C3 async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield 1; >x : any @@ -50,14 +50,14 @@ class C5 { >C5 : C5 async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -80,7 +80,7 @@ class C7 { >C7 : C7 async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/emitter.asyncGenerators.classMethods.esnext.types b/tests/baselines/reference/emitter.asyncGenerators.classMethods.esnext.types index 1232130a389..f2f5f4d7503 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.classMethods.esnext.types +++ b/tests/baselines/reference/emitter.asyncGenerators.classMethods.esnext.types @@ -23,7 +23,7 @@ class C3 { >C3 : C3 async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield 1; >x : any @@ -50,14 +50,14 @@ class C5 { >C5 : C5 async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -80,7 +80,7 @@ class C7 { >C7 : C7 async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es2015.types b/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es2015.types index 0e434639906..15ff1298b21 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es2015.types +++ b/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es2015.types @@ -12,7 +12,7 @@ async function * f2() { } === tests/cases/conformance/emitter/es2015/asyncGenerators/F3.ts === async function * f3() { ->f3 : () => AsyncIterableIterator<1> +>f3 : () => AsyncIterableIterator const x = yield 1; >x : any @@ -31,14 +31,14 @@ async function * f4() { } === tests/cases/conformance/emitter/es2015/asyncGenerators/F5.ts === async function * f5() { ->f5 : () => AsyncIterableIterator<1> +>f5 : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -53,7 +53,7 @@ async function * f6() { } === tests/cases/conformance/emitter/es2015/asyncGenerators/F7.ts === async function * f7() { ->f7 : () => AsyncIterableIterator<1> +>f7 : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es5.types b/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es5.types index 9ebd2659ef4..6220f5efd1e 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es5.types +++ b/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es5.types @@ -12,7 +12,7 @@ async function * f2() { } === tests/cases/conformance/emitter/es5/asyncGenerators/F3.ts === async function * f3() { ->f3 : () => AsyncIterableIterator<1> +>f3 : () => AsyncIterableIterator const x = yield 1; >x : any @@ -31,14 +31,14 @@ async function * f4() { } === tests/cases/conformance/emitter/es5/asyncGenerators/F5.ts === async function * f5() { ->f5 : () => AsyncIterableIterator<1> +>f5 : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -53,7 +53,7 @@ async function * f6() { } === tests/cases/conformance/emitter/es5/asyncGenerators/F7.ts === async function * f7() { ->f7 : () => AsyncIterableIterator<1> +>f7 : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.esnext.types b/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.esnext.types index 4e61c903227..c0d80117746 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.esnext.types +++ b/tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.esnext.types @@ -12,7 +12,7 @@ async function * f2() { } === tests/cases/conformance/emitter/esnext/asyncGenerators/F3.ts === async function * f3() { ->f3 : () => AsyncIterableIterator<1> +>f3 : () => AsyncIterableIterator const x = yield 1; >x : any @@ -31,14 +31,14 @@ async function * f4() { } === tests/cases/conformance/emitter/esnext/asyncGenerators/F5.ts === async function * f5() { ->f5 : () => AsyncIterableIterator<1> +>f5 : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -53,7 +53,7 @@ async function * f6() { } === tests/cases/conformance/emitter/esnext/asyncGenerators/F7.ts === async function * f7() { ->f7 : () => AsyncIterableIterator<1> +>f7 : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es2015.types b/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es2015.types index 83d65ce5246..1db2126b7ed 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es2015.types +++ b/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es2015.types @@ -14,8 +14,8 @@ const f2 = async function * () { } === tests/cases/conformance/emitter/es2015/asyncGenerators/F3.ts === const f3 = async function * () { ->f3 : () => AsyncIterableIterator<1> ->async function * () { const x = yield 1;} : () => AsyncIterableIterator<1> +>f3 : () => AsyncIterableIterator +>async function * () { const x = yield 1;} : () => AsyncIterableIterator const x = yield 1; >x : any @@ -35,15 +35,15 @@ const f4 = async function * () { } === tests/cases/conformance/emitter/es2015/asyncGenerators/F5.ts === const f5 = async function * () { ->f5 : () => AsyncIterableIterator<1> ->async function * () { const x = yield* (async function*() { yield 1; })();} : () => AsyncIterableIterator<1> +>f5 : () => AsyncIterableIterator +>async function * () { const x = yield* (async function*() { yield 1; })();} : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -59,8 +59,8 @@ const f6 = async function * () { } === tests/cases/conformance/emitter/es2015/asyncGenerators/F7.ts === const f7 = async function * () { ->f7 : () => AsyncIterableIterator<1> ->async function * () { return 1;} : () => AsyncIterableIterator<1> +>f7 : () => AsyncIterableIterator +>async function * () { return 1;} : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es5.types b/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es5.types index 7d736b2327c..e9da600bdbf 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es5.types +++ b/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es5.types @@ -14,8 +14,8 @@ const f2 = async function * () { } === tests/cases/conformance/emitter/es5/asyncGenerators/F3.ts === const f3 = async function * () { ->f3 : () => AsyncIterableIterator<1> ->async function * () { const x = yield 1;} : () => AsyncIterableIterator<1> +>f3 : () => AsyncIterableIterator +>async function * () { const x = yield 1;} : () => AsyncIterableIterator const x = yield 1; >x : any @@ -35,15 +35,15 @@ const f4 = async function * () { } === tests/cases/conformance/emitter/es5/asyncGenerators/F5.ts === const f5 = async function * () { ->f5 : () => AsyncIterableIterator<1> ->async function * () { const x = yield* (async function*() { yield 1; })();} : () => AsyncIterableIterator<1> +>f5 : () => AsyncIterableIterator +>async function * () { const x = yield* (async function*() { yield 1; })();} : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -59,8 +59,8 @@ const f6 = async function * () { } === tests/cases/conformance/emitter/es5/asyncGenerators/F7.ts === const f7 = async function * () { ->f7 : () => AsyncIterableIterator<1> ->async function * () { return 1;} : () => AsyncIterableIterator<1> +>f7 : () => AsyncIterableIterator +>async function * () { return 1;} : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.esnext.types b/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.esnext.types index 6c40f9cebb1..5802bc10a2d 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.esnext.types +++ b/tests/baselines/reference/emitter.asyncGenerators.functionExpressions.esnext.types @@ -14,8 +14,8 @@ const f2 = async function * () { } === tests/cases/conformance/emitter/esnext/asyncGenerators/F3.ts === const f3 = async function * () { ->f3 : () => AsyncIterableIterator<1> ->async function * () { const x = yield 1;} : () => AsyncIterableIterator<1> +>f3 : () => AsyncIterableIterator +>async function * () { const x = yield 1;} : () => AsyncIterableIterator const x = yield 1; >x : any @@ -35,15 +35,15 @@ const f4 = async function * () { } === tests/cases/conformance/emitter/esnext/asyncGenerators/F5.ts === const f5 = async function * () { ->f5 : () => AsyncIterableIterator<1> ->async function * () { const x = yield* (async function*() { yield 1; })();} : () => AsyncIterableIterator<1> +>f5 : () => AsyncIterableIterator +>async function * () { const x = yield* (async function*() { yield 1; })();} : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -59,8 +59,8 @@ const f6 = async function * () { } === tests/cases/conformance/emitter/esnext/asyncGenerators/F7.ts === const f7 = async function * () { ->f7 : () => AsyncIterableIterator<1> ->async function * () { return 1;} : () => AsyncIterableIterator<1> +>f7 : () => AsyncIterableIterator +>async function * () { return 1;} : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.es2015.types b/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.es2015.types index 59c5bcfa167..9e47fc9d989 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.es2015.types +++ b/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.es2015.types @@ -22,11 +22,11 @@ const o2 = { } === tests/cases/conformance/emitter/es2015/asyncGenerators/O3.ts === const o3 = { ->o3 : { f(): AsyncIterableIterator<1>; } ->{ async * f() { const x = yield 1; }} : { f(): AsyncIterableIterator<1>; } +>o3 : { f(): AsyncIterableIterator; } +>{ async * f() { const x = yield 1; }} : { f(): AsyncIterableIterator; } async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield 1; >x : any @@ -51,18 +51,18 @@ const o4 = { } === tests/cases/conformance/emitter/es2015/asyncGenerators/O5.ts === const o5 = { ->o5 : { f(): AsyncIterableIterator<1>; } ->{ async * f() { const x = yield* (async function*() { yield 1; })(); }} : { f(): AsyncIterableIterator<1>; } +>o5 : { f(): AsyncIterableIterator; } +>{ async * f() { const x = yield* (async function*() { yield 1; })(); }} : { f(): AsyncIterableIterator; } async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -83,11 +83,11 @@ const o6 = { } === tests/cases/conformance/emitter/es2015/asyncGenerators/O7.ts === const o7 = { ->o7 : { f(): AsyncIterableIterator<1>; } ->{ async * f() { return 1; }} : { f(): AsyncIterableIterator<1>; } +>o7 : { f(): AsyncIterableIterator; } +>{ async * f() { return 1; }} : { f(): AsyncIterableIterator; } async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.es5.types b/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.es5.types index 3e7ead2f737..39000760508 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.es5.types +++ b/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.es5.types @@ -22,11 +22,11 @@ const o2 = { } === tests/cases/conformance/emitter/es5/asyncGenerators/O3.ts === const o3 = { ->o3 : { f(): AsyncIterableIterator<1>; } ->{ async * f() { const x = yield 1; }} : { f(): AsyncIterableIterator<1>; } +>o3 : { f(): AsyncIterableIterator; } +>{ async * f() { const x = yield 1; }} : { f(): AsyncIterableIterator; } async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield 1; >x : any @@ -51,18 +51,18 @@ const o4 = { } === tests/cases/conformance/emitter/es5/asyncGenerators/O5.ts === const o5 = { ->o5 : { f(): AsyncIterableIterator<1>; } ->{ async * f() { const x = yield* (async function*() { yield 1; })(); }} : { f(): AsyncIterableIterator<1>; } +>o5 : { f(): AsyncIterableIterator; } +>{ async * f() { const x = yield* (async function*() { yield 1; })(); }} : { f(): AsyncIterableIterator; } async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -83,11 +83,11 @@ const o6 = { } === tests/cases/conformance/emitter/es5/asyncGenerators/O7.ts === const o7 = { ->o7 : { f(): AsyncIterableIterator<1>; } ->{ async * f() { return 1; }} : { f(): AsyncIterableIterator<1>; } +>o7 : { f(): AsyncIterableIterator; } +>{ async * f() { return 1; }} : { f(): AsyncIterableIterator; } async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.esnext.types b/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.esnext.types index 9e5aad8af23..a05b5326b2c 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.esnext.types +++ b/tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.esnext.types @@ -22,11 +22,11 @@ const o2 = { } === tests/cases/conformance/emitter/esnext/asyncGenerators/O3.ts === const o3 = { ->o3 : { f(): AsyncIterableIterator<1>; } ->{ async * f() { const x = yield 1; }} : { f(): AsyncIterableIterator<1>; } +>o3 : { f(): AsyncIterableIterator; } +>{ async * f() { const x = yield 1; }} : { f(): AsyncIterableIterator; } async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield 1; >x : any @@ -51,18 +51,18 @@ const o4 = { } === tests/cases/conformance/emitter/esnext/asyncGenerators/O5.ts === const o5 = { ->o5 : { f(): AsyncIterableIterator<1>; } ->{ async * f() { const x = yield* (async function*() { yield 1; })(); }} : { f(): AsyncIterableIterator<1>; } +>o5 : { f(): AsyncIterableIterator; } +>{ async * f() { const x = yield* (async function*() { yield 1; })(); }} : { f(): AsyncIterableIterator; } async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator const x = yield* (async function*() { yield 1; })(); >x : any >yield* (async function*() { yield 1; })() : any ->(async function*() { yield 1; })() : AsyncIterableIterator<1> ->(async function*() { yield 1; }) : () => AsyncIterableIterator<1> ->async function*() { yield 1; } : () => AsyncIterableIterator<1> +>(async function*() { yield 1; })() : AsyncIterableIterator +>(async function*() { yield 1; }) : () => AsyncIterableIterator +>async function*() { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -83,11 +83,11 @@ const o6 = { } === tests/cases/conformance/emitter/esnext/asyncGenerators/O7.ts === const o7 = { ->o7 : { f(): AsyncIterableIterator<1>; } ->{ async * f() { return 1; }} : { f(): AsyncIterableIterator<1>; } +>o7 : { f(): AsyncIterableIterator; } +>{ async * f() { return 1; }} : { f(): AsyncIterableIterator; } async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator return 1; >1 : 1 diff --git a/tests/baselines/reference/generatorES6_2.types b/tests/baselines/reference/generatorES6_2.types index 61a2adbc697..a95a0008d4f 100644 --- a/tests/baselines/reference/generatorES6_2.types +++ b/tests/baselines/reference/generatorES6_2.types @@ -3,7 +3,7 @@ class C { >C : C public * foo() { ->foo : () => IterableIterator<1> +>foo : () => IterableIterator yield 1 >yield 1 : any diff --git a/tests/baselines/reference/generatorES6_3.types b/tests/baselines/reference/generatorES6_3.types index 9ecd01d6e23..e237cbd3510 100644 --- a/tests/baselines/reference/generatorES6_3.types +++ b/tests/baselines/reference/generatorES6_3.types @@ -1,7 +1,7 @@ === tests/cases/compiler/generatorES6_3.ts === var v = function*() { ->v : () => IterableIterator<0> ->function*() { yield 0} : () => IterableIterator<0> +>v : () => IterableIterator +>function*() { yield 0} : () => IterableIterator yield 0 >yield 0 : any diff --git a/tests/baselines/reference/generatorES6_4.types b/tests/baselines/reference/generatorES6_4.types index 786e7b64020..fa19d8f3ae2 100644 --- a/tests/baselines/reference/generatorES6_4.types +++ b/tests/baselines/reference/generatorES6_4.types @@ -1,10 +1,10 @@ === tests/cases/compiler/generatorES6_4.ts === var v = { ->v : { foo(): IterableIterator<0>; } ->{ *foo() { yield 0 }} : { foo(): IterableIterator<0>; } +>v : { foo(): IterableIterator; } +>{ *foo() { yield 0 }} : { foo(): IterableIterator; } *foo() { ->foo : () => IterableIterator<0> +>foo : () => IterableIterator yield 0 >yield 0 : any diff --git a/tests/baselines/reference/generatorTypeCheck15.types b/tests/baselines/reference/generatorTypeCheck15.types index 3851d8e56a4..33537836c12 100644 --- a/tests/baselines/reference/generatorTypeCheck15.types +++ b/tests/baselines/reference/generatorTypeCheck15.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck15.ts === function* g() { ->g : () => IterableIterator<""> +>g : () => IterableIterator return ""; >"" : "" diff --git a/tests/baselines/reference/generatorTypeCheck33.types b/tests/baselines/reference/generatorTypeCheck33.types index 707bf7beccd..d6b29936530 100644 --- a/tests/baselines/reference/generatorTypeCheck33.types +++ b/tests/baselines/reference/generatorTypeCheck33.types @@ -1,13 +1,13 @@ === tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck33.ts === function* g() { ->g : () => IterableIterator<0> +>g : () => IterableIterator yield 0; >yield 0 : any >0 : 0 function* g2() { ->g2 : () => IterableIterator<""> +>g2 : () => IterableIterator yield ""; >yield "" : any diff --git a/tests/baselines/reference/generatorTypeCheck34.types b/tests/baselines/reference/generatorTypeCheck34.types index 239c5ff1493..f25eefb72f7 100644 --- a/tests/baselines/reference/generatorTypeCheck34.types +++ b/tests/baselines/reference/generatorTypeCheck34.types @@ -1,13 +1,13 @@ === tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck34.ts === function* g() { ->g : () => IterableIterator<0> +>g : () => IterableIterator yield 0; >yield 0 : any >0 : 0 function* g2() { ->g2 : () => IterableIterator<""> +>g2 : () => IterableIterator return ""; >"" : "" diff --git a/tests/baselines/reference/generatorTypeCheck35.types b/tests/baselines/reference/generatorTypeCheck35.types index dcd5ab4be84..333b653a501 100644 --- a/tests/baselines/reference/generatorTypeCheck35.types +++ b/tests/baselines/reference/generatorTypeCheck35.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck35.ts === function* g() { ->g : () => IterableIterator<0> +>g : () => IterableIterator yield 0; >yield 0 : any diff --git a/tests/baselines/reference/generatorTypeCheck38.types b/tests/baselines/reference/generatorTypeCheck38.types index 31fe452e656..15b8528b345 100644 --- a/tests/baselines/reference/generatorTypeCheck38.types +++ b/tests/baselines/reference/generatorTypeCheck38.types @@ -3,7 +3,7 @@ var yield; >yield : any function* g() { ->g : () => IterableIterator<0> +>g : () => IterableIterator yield 0; >yield 0 : any diff --git a/tests/baselines/reference/generatorTypeCheck41.types b/tests/baselines/reference/generatorTypeCheck41.types index 1a9ea21f978..8e59ce18860 100644 --- a/tests/baselines/reference/generatorTypeCheck41.types +++ b/tests/baselines/reference/generatorTypeCheck41.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck41.ts === function* g() { ->g : () => IterableIterator<0> +>g : () => IterableIterator let x = { >x : { [x: number]: number; } diff --git a/tests/baselines/reference/generatorTypeCheck42.types b/tests/baselines/reference/generatorTypeCheck42.types index 79b2516051e..f7281d60afe 100644 --- a/tests/baselines/reference/generatorTypeCheck42.types +++ b/tests/baselines/reference/generatorTypeCheck42.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck42.ts === function* g() { ->g : () => IterableIterator<0> +>g : () => IterableIterator let x = { >x : { [x: number]: () => void; } diff --git a/tests/baselines/reference/generatorTypeCheck43.types b/tests/baselines/reference/generatorTypeCheck43.types index 754d3fee814..3e8ec02672a 100644 --- a/tests/baselines/reference/generatorTypeCheck43.types +++ b/tests/baselines/reference/generatorTypeCheck43.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck43.ts === function* g() { ->g : () => IterableIterator<0> +>g : () => IterableIterator let x = { >x : { [x: number]: () => IterableIterator; } diff --git a/tests/baselines/reference/generatorTypeCheck44.types b/tests/baselines/reference/generatorTypeCheck44.types index e06b8961ca0..381feb30f3c 100644 --- a/tests/baselines/reference/generatorTypeCheck44.types +++ b/tests/baselines/reference/generatorTypeCheck44.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck44.ts === function* g() { ->g : () => IterableIterator<0> +>g : () => IterableIterator let x = { >x : { [x: number]: number; } diff --git a/tests/baselines/reference/generatorTypeCheck49.types b/tests/baselines/reference/generatorTypeCheck49.types index 6ac2b6acce8..f73978d1a09 100644 --- a/tests/baselines/reference/generatorTypeCheck49.types +++ b/tests/baselines/reference/generatorTypeCheck49.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck49.ts === function* g() { ->g : () => IterableIterator<0> +>g : () => IterableIterator yield 0; >yield 0 : any diff --git a/tests/baselines/reference/generatorTypeCheck51.types b/tests/baselines/reference/generatorTypeCheck51.types index ca50f640301..1563ee5e7d3 100644 --- a/tests/baselines/reference/generatorTypeCheck51.types +++ b/tests/baselines/reference/generatorTypeCheck51.types @@ -3,7 +3,7 @@ function* g() { >g : () => IterableIterator function* h() { ->h : () => IterableIterator<0> +>h : () => IterableIterator yield 0; >yield 0 : any diff --git a/tests/baselines/reference/generatorTypeCheck63.errors.txt b/tests/baselines/reference/generatorTypeCheck63.errors.txt index 1466530dd0c..2a1935fd906 100644 --- a/tests/baselines/reference/generatorTypeCheck63.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck63.errors.txt @@ -3,9 +3,9 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,61): err Type 'State | 1' is not assignable to type 'StrategicState'. Type '1' has no properties in common with type 'StrategicState'. tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(29,70): error TS7025: Generator implicitly has type 'IterableIterator' because it does not yield any values. Consider supplying a return type. -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(32,62): error TS2345: Argument of type '(state: State) => IterableIterator<1>' is not assignable to parameter of type '(a: State) => IterableIterator'. - Type 'IterableIterator<1>' is not assignable to type 'IterableIterator'. - Type '1' is not assignable to type 'State'. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(32,62): error TS2345: Argument of type '(state: State) => IterableIterator' is not assignable to parameter of type '(a: State) => IterableIterator'. + Type 'IterableIterator' is not assignable to type 'IterableIterator'. + Type 'number' is not assignable to type 'State'. tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,62): error TS2345: Argument of type '(state: State) => IterableIterator' is not assignable to parameter of type '(a: StrategicState) => IterableIterator'. Type 'IterableIterator' is not assignable to type 'IterableIterator'. @@ -51,9 +51,9 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,62): err export const Nothing2: Strategy = strategy("Nothing", function* (state: State) { ~~~~~~~~ -!!! error TS2345: Argument of type '(state: State) => IterableIterator<1>' is not assignable to parameter of type '(a: State) => IterableIterator'. -!!! error TS2345: Type 'IterableIterator<1>' is not assignable to type 'IterableIterator'. -!!! error TS2345: Type '1' is not assignable to type 'State'. +!!! error TS2345: Argument of type '(state: State) => IterableIterator' is not assignable to parameter of type '(a: State) => IterableIterator'. +!!! error TS2345: Type 'IterableIterator' is not assignable to type 'IterableIterator'. +!!! error TS2345: Type 'number' is not assignable to type 'State'. return 1; }); diff --git a/tests/baselines/reference/generatorTypeCheck63.types b/tests/baselines/reference/generatorTypeCheck63.types index cd41a1776b8..8fc2054bd6e 100644 --- a/tests/baselines/reference/generatorTypeCheck63.types +++ b/tests/baselines/reference/generatorTypeCheck63.types @@ -107,7 +107,7 @@ export const Nothing2: Strategy = strategy("Nothing", function* (state: S >strategy("Nothing", function* (state: State) { return 1;}) : any >strategy : (stratName: string, gen: (a: T) => IterableIterator) => (a: T) => IterableIterator >"Nothing" : "Nothing" ->function* (state: State) { return 1;} : (state: State) => IterableIterator<1> +>function* (state: State) { return 1;} : (state: State) => IterableIterator >state : State >State : State diff --git a/tests/baselines/reference/parser.asyncGenerators.classMethods.esnext.types b/tests/baselines/reference/parser.asyncGenerators.classMethods.esnext.types index ad6d810b0cb..254d983caaa 100644 --- a/tests/baselines/reference/parser.asyncGenerators.classMethods.esnext.types +++ b/tests/baselines/reference/parser.asyncGenerators.classMethods.esnext.types @@ -151,7 +151,7 @@ class C14 { >C14 : C14 async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator yield 1; >yield 1 : any @@ -175,7 +175,7 @@ class C16 { >C16 : C16 async * f() { ->f : () => AsyncIterableIterator +>f : () => AsyncIterableIterator yield * []; >yield * [] : any diff --git a/tests/baselines/reference/parser.asyncGenerators.functionDeclarations.esnext.types b/tests/baselines/reference/parser.asyncGenerators.functionDeclarations.esnext.types index 772de158358..c27e9209611 100644 --- a/tests/baselines/reference/parser.asyncGenerators.functionDeclarations.esnext.types +++ b/tests/baselines/reference/parser.asyncGenerators.functionDeclarations.esnext.types @@ -95,7 +95,7 @@ async function * f13() { } === tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldWithValueIsOk.ts === async function * f14() { ->f14 : () => AsyncIterableIterator<1> +>f14 : () => AsyncIterableIterator yield 1; >yield 1 : any @@ -111,7 +111,7 @@ async function * f15() { } === tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldStarWithValueIsOk.ts === async function * f16() { ->f16 : () => AsyncIterableIterator +>f16 : () => AsyncIterableIterator yield * []; >yield * [] : any diff --git a/tests/baselines/reference/parser.asyncGenerators.functionExpressions.esnext.types b/tests/baselines/reference/parser.asyncGenerators.functionExpressions.esnext.types index 557956a3344..09b57979699 100644 --- a/tests/baselines/reference/parser.asyncGenerators.functionExpressions.esnext.types +++ b/tests/baselines/reference/parser.asyncGenerators.functionExpressions.esnext.types @@ -122,8 +122,8 @@ const f13 = async function * () { }; === tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldWithValueIsOk.ts === const f14 = async function * () { ->f14 : () => AsyncIterableIterator<1> ->async function * () { yield 1;} : () => AsyncIterableIterator<1> +>f14 : () => AsyncIterableIterator +>async function * () { yield 1;} : () => AsyncIterableIterator yield 1; >yield 1 : any @@ -142,8 +142,8 @@ const f15 = async function * () { }; === tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldStarWithValueIsOk.ts === const f16 = async function * () { ->f16 : () => AsyncIterableIterator ->async function * () { yield * [];} : () => AsyncIterableIterator +>f16 : () => AsyncIterableIterator +>async function * () { yield * [];} : () => AsyncIterableIterator yield * []; >yield * [] : any diff --git a/tests/baselines/reference/parser.asyncGenerators.objectLiteralMethods.esnext.types b/tests/baselines/reference/parser.asyncGenerators.objectLiteralMethods.esnext.types index d352b541585..59ed6e16745 100644 --- a/tests/baselines/reference/parser.asyncGenerators.objectLiteralMethods.esnext.types +++ b/tests/baselines/reference/parser.asyncGenerators.objectLiteralMethods.esnext.types @@ -163,11 +163,11 @@ const o13 = { }; === tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldWithValueIsOk.ts === const o14 = { ->o14 : { f(): AsyncIterableIterator<1>; } ->{ async * f() { yield 1; }} : { f(): AsyncIterableIterator<1>; } +>o14 : { f(): AsyncIterableIterator; } +>{ async * f() { yield 1; }} : { f(): AsyncIterableIterator; } async * f() { ->f : () => AsyncIterableIterator<1> +>f : () => AsyncIterableIterator yield 1; >yield 1 : any @@ -189,11 +189,11 @@ const o15 = { }; === tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldStarWithValueIsOk.ts === const o16 = { ->o16 : { f(): AsyncIterableIterator; } ->{ async * f() { yield * []; }} : { f(): AsyncIterableIterator; } +>o16 : { f(): AsyncIterableIterator; } +>{ async * f() { yield * []; }} : { f(): AsyncIterableIterator; } async * f() { ->f : () => AsyncIterableIterator +>f : () => AsyncIterableIterator yield * []; >yield * [] : any diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.types b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.types index e4496aa4e8b..dfd4e522def 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.types +++ b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts === function* gen() { ->gen : () => IterableIterator<10> +>gen : () => IterableIterator // Once this is supported, yield *must* be parenthesized. var x = `abc${ yield 10 }def`; diff --git a/tests/baselines/reference/types.asyncGenerators.esnext.1.types b/tests/baselines/reference/types.asyncGenerators.esnext.1.types index 1a72da228e7..6e29e9cc95c 100644 --- a/tests/baselines/reference/types.asyncGenerators.esnext.1.types +++ b/tests/baselines/reference/types.asyncGenerators.esnext.1.types @@ -9,7 +9,7 @@ async function * inferReturnType2() { >yield : any } async function * inferReturnType3() { ->inferReturnType3 : () => AsyncIterableIterator<1> +>inferReturnType3 : () => AsyncIterableIterator yield 1; >yield 1 : any @@ -63,20 +63,20 @@ async function * inferReturnType7() { >1 : 1 } async function * inferReturnType8() { ->inferReturnType8 : () => AsyncIterableIterator<1> +>inferReturnType8 : () => AsyncIterableIterator yield* (async function * () { yield 1; })(); >yield* (async function * () { yield 1; })() : any ->(async function * () { yield 1; })() : AsyncIterableIterator<1> ->(async function * () { yield 1; }) : () => AsyncIterableIterator<1> ->async function * () { yield 1; } : () => AsyncIterableIterator<1> +>(async function * () { yield 1; })() : AsyncIterableIterator +>(async function * () { yield 1; }) : () => AsyncIterableIterator +>async function * () { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } const assignability1: () => AsyncIterableIterator = async function * () { >assignability1 : () => AsyncIterableIterator >AsyncIterableIterator : AsyncIterableIterator ->async function * () { yield 1;} : () => AsyncIterableIterator<1> +>async function * () { yield 1;} : () => AsyncIterableIterator yield 1; >yield 1 : any @@ -127,13 +127,13 @@ const assignability4: () => AsyncIterableIterator = async function * () const assignability5: () => AsyncIterableIterator = async function * () { >assignability5 : () => AsyncIterableIterator >AsyncIterableIterator : AsyncIterableIterator ->async function * () { yield* (async function * () { yield 1; })();} : () => AsyncIterableIterator<1> +>async function * () { yield* (async function * () { yield 1; })();} : () => AsyncIterableIterator yield* (async function * () { yield 1; })(); >yield* (async function * () { yield 1; })() : any ->(async function * () { yield 1; })() : AsyncIterableIterator<1> ->(async function * () { yield 1; }) : () => AsyncIterableIterator<1> ->async function * () { yield 1; } : () => AsyncIterableIterator<1> +>(async function * () { yield 1; })() : AsyncIterableIterator +>(async function * () { yield 1; }) : () => AsyncIterableIterator +>async function * () { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 @@ -141,7 +141,7 @@ const assignability5: () => AsyncIterableIterator = async function * () const assignability6: () => AsyncIterable = async function * () { >assignability6 : () => AsyncIterable >AsyncIterable : AsyncIterable ->async function * () { yield 1;} : () => AsyncIterableIterator<1> +>async function * () { yield 1;} : () => AsyncIterableIterator yield 1; >yield 1 : any @@ -192,13 +192,13 @@ const assignability9: () => AsyncIterable = async function * () { const assignability10: () => AsyncIterable = async function * () { >assignability10 : () => AsyncIterable >AsyncIterable : AsyncIterable ->async function * () { yield* (async function * () { yield 1; })();} : () => AsyncIterableIterator<1> +>async function * () { yield* (async function * () { yield 1; })();} : () => AsyncIterableIterator yield* (async function * () { yield 1; })(); >yield* (async function * () { yield 1; })() : any ->(async function * () { yield 1; })() : AsyncIterableIterator<1> ->(async function * () { yield 1; }) : () => AsyncIterableIterator<1> ->async function * () { yield 1; } : () => AsyncIterableIterator<1> +>(async function * () { yield 1; })() : AsyncIterableIterator +>(async function * () { yield 1; }) : () => AsyncIterableIterator +>async function * () { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 @@ -206,7 +206,7 @@ const assignability10: () => AsyncIterable = async function * () { const assignability11: () => AsyncIterator = async function * () { >assignability11 : () => AsyncIterator >AsyncIterator : AsyncIterator ->async function * () { yield 1;} : () => AsyncIterableIterator<1> +>async function * () { yield 1;} : () => AsyncIterableIterator yield 1; >yield 1 : any @@ -257,13 +257,13 @@ const assignability14: () => AsyncIterator = async function * () { const assignability15: () => AsyncIterator = async function * () { >assignability15 : () => AsyncIterator >AsyncIterator : AsyncIterator ->async function * () { yield* (async function * () { yield 1; })();} : () => AsyncIterableIterator<1> +>async function * () { yield* (async function * () { yield 1; })();} : () => AsyncIterableIterator yield* (async function * () { yield 1; })(); >yield* (async function * () { yield 1; })() : any ->(async function * () { yield 1; })() : AsyncIterableIterator<1> ->(async function * () { yield 1; }) : () => AsyncIterableIterator<1> ->async function * () { yield 1; } : () => AsyncIterableIterator<1> +>(async function * () { yield 1; })() : AsyncIterableIterator +>(async function * () { yield 1; }) : () => AsyncIterableIterator +>async function * () { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 @@ -317,9 +317,9 @@ async function * explicitReturnType5(): AsyncIterableIterator { yield* (async function * () { yield 1; })(); >yield* (async function * () { yield 1; })() : any ->(async function * () { yield 1; })() : AsyncIterableIterator<1> ->(async function * () { yield 1; }) : () => AsyncIterableIterator<1> ->async function * () { yield 1; } : () => AsyncIterableIterator<1> +>(async function * () { yield 1; })() : AsyncIterableIterator +>(async function * () { yield 1; }) : () => AsyncIterableIterator +>async function * () { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -372,9 +372,9 @@ async function * explicitReturnType10(): AsyncIterable { yield* (async function * () { yield 1; })(); >yield* (async function * () { yield 1; })() : any ->(async function * () { yield 1; })() : AsyncIterableIterator<1> ->(async function * () { yield 1; }) : () => AsyncIterableIterator<1> ->async function * () { yield 1; } : () => AsyncIterableIterator<1> +>(async function * () { yield 1; })() : AsyncIterableIterator +>(async function * () { yield 1; }) : () => AsyncIterableIterator +>async function * () { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } @@ -427,9 +427,9 @@ async function * explicitReturnType15(): AsyncIterator { yield* (async function * () { yield 1; })(); >yield* (async function * () { yield 1; })() : any ->(async function * () { yield 1; })() : AsyncIterableIterator<1> ->(async function * () { yield 1; }) : () => AsyncIterableIterator<1> ->async function * () { yield 1; } : () => AsyncIterableIterator<1> +>(async function * () { yield 1; })() : AsyncIterableIterator +>(async function * () { yield 1; }) : () => AsyncIterableIterator +>async function * () { yield 1; } : () => AsyncIterableIterator >yield 1 : any >1 : 1 } diff --git a/tests/baselines/reference/types.asyncGenerators.esnext.2.errors.txt b/tests/baselines/reference/types.asyncGenerators.esnext.2.errors.txt index 64d7980578c..a6a0243ded6 100644 --- a/tests/baselines/reference/types.asyncGenerators.esnext.2.errors.txt +++ b/tests/baselines/reference/types.asyncGenerators.esnext.2.errors.txt @@ -1,24 +1,13 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(2,12): error TS2504: Type must have a '[Symbol.asyncIterator]()' method that returns an async iterator. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(8,12): error TS2504: Type must have a '[Symbol.asyncIterator]()' method that returns an async iterator. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(10,7): error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterableIterator'. - Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterableIterator'. - Type '"a"' is not assignable to type 'number'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(13,7): error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterableIterator'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(10,7): error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterableIterator'. Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterableIterator'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(16,7): error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterableIterator'. - Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterableIterator'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(19,7): error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterable'. - Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterable'. - Types of property '[Symbol.asyncIterator]' are incompatible. - Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterator'. - Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterator'. - Types of property 'next' are incompatible. - Type '(value?: any) => Promise>' is not assignable to type '(value?: any) => Promise>'. - Type 'Promise>' is not assignable to type 'Promise>'. - Type 'IteratorResult<"a">' is not assignable to type 'IteratorResult'. - Type '"a"' is not assignable to type 'number'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(22,7): error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterable'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(13,7): error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterableIterator'. + Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterableIterator'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(16,7): error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterableIterator'. + Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterableIterator'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(19,7): error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterable'. Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterable'. Types of property '[Symbol.asyncIterator]' are incompatible. Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterator'. @@ -28,23 +17,25 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts( Type 'Promise>' is not assignable to type 'Promise>'. Type 'IteratorResult' is not assignable to type 'IteratorResult'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(25,7): error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterable'. - Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterable'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(28,7): error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterator'. - Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterator'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(22,7): error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterable'. + Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterable'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(25,7): error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterable'. + Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterable'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(28,7): error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterator'. + Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterator'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(31,7): error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterator'. Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterator'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(34,7): error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterator'. - Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterator'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(34,7): error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterator'. + Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterator'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(38,11): error TS2322: Type '"a"' is not assignable to type 'number'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(41,12): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(44,12): error TS2322: Type '"a"' is not assignable to type 'number'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(44,12): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(47,11): error TS2322: Type '"a"' is not assignable to type 'number'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(50,12): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(53,12): error TS2322: Type '"a"' is not assignable to type 'number'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(53,12): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(56,11): error TS2322: Type '"a"' is not assignable to type 'number'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(59,12): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(62,12): error TS2322: Type '"a"' is not assignable to type 'number'. +tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(62,12): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(64,42): error TS2322: Type 'AsyncIterableIterator' is not assignable to type 'IterableIterator'. Property '[Symbol.iterator]' is missing in type 'AsyncIterableIterator'. tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(67,42): error TS2322: Type 'AsyncIterableIterator' is not assignable to type 'Iterable'. @@ -73,40 +64,25 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts( } const assignability1: () => AsyncIterableIterator = async function * () { ~~~~~~~~~~~~~~ -!!! error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterableIterator'. -!!! error TS2322: Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterableIterator'. -!!! error TS2322: Type '"a"' is not assignable to type 'number'. +!!! error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterableIterator'. +!!! error TS2322: Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterableIterator'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. yield "a"; }; const assignability2: () => AsyncIterableIterator = async function * () { ~~~~~~~~~~~~~~ !!! error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterableIterator'. !!! error TS2322: Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterableIterator'. -!!! error TS2322: Type 'string' is not assignable to type 'number'. yield* ["a", "b"]; }; const assignability3: () => AsyncIterableIterator = async function * () { ~~~~~~~~~~~~~~ -!!! error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterableIterator'. -!!! error TS2322: Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterableIterator'. +!!! error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterableIterator'. +!!! error TS2322: Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterableIterator'. yield* (async function * () { yield "a"; })(); }; const assignability4: () => AsyncIterable = async function * () { ~~~~~~~~~~~~~~ -!!! error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterable'. -!!! error TS2322: Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterable'. -!!! error TS2322: Types of property '[Symbol.asyncIterator]' are incompatible. -!!! error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterator'. -!!! error TS2322: Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterator'. -!!! error TS2322: Types of property 'next' are incompatible. -!!! error TS2322: Type '(value?: any) => Promise>' is not assignable to type '(value?: any) => Promise>'. -!!! error TS2322: Type 'Promise>' is not assignable to type 'Promise>'. -!!! error TS2322: Type 'IteratorResult<"a">' is not assignable to type 'IteratorResult'. -!!! error TS2322: Type '"a"' is not assignable to type 'number'. - yield "a"; - }; - const assignability5: () => AsyncIterable = async function * () { - ~~~~~~~~~~~~~~ !!! error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterable'. !!! error TS2322: Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterable'. !!! error TS2322: Types of property '[Symbol.asyncIterator]' are incompatible. @@ -117,18 +93,24 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts( !!! error TS2322: Type 'Promise>' is not assignable to type 'Promise>'. !!! error TS2322: Type 'IteratorResult' is not assignable to type 'IteratorResult'. !!! error TS2322: Type 'string' is not assignable to type 'number'. + yield "a"; + }; + const assignability5: () => AsyncIterable = async function * () { + ~~~~~~~~~~~~~~ +!!! error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterable'. +!!! error TS2322: Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterable'. yield* ["a", "b"]; }; const assignability6: () => AsyncIterable = async function * () { ~~~~~~~~~~~~~~ -!!! error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterable'. -!!! error TS2322: Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterable'. +!!! error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterable'. +!!! error TS2322: Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterable'. yield* (async function * () { yield "a"; })(); }; const assignability7: () => AsyncIterator = async function * () { ~~~~~~~~~~~~~~ -!!! error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterator'. -!!! error TS2322: Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterator'. +!!! error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterator'. +!!! error TS2322: Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterator'. yield "a"; }; const assignability8: () => AsyncIterator = async function * () { @@ -139,8 +121,8 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts( }; const assignability9: () => AsyncIterator = async function * () { ~~~~~~~~~~~~~~ -!!! error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterator'. -!!! error TS2322: Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterator'. +!!! error TS2322: Type '() => AsyncIterableIterator' is not assignable to type '() => AsyncIterator'. +!!! error TS2322: Type 'AsyncIterableIterator' is not assignable to type 'AsyncIterator'. yield* (async function * () { yield "a"; })(); }; async function * explicitReturnType1(): AsyncIterableIterator { @@ -156,7 +138,7 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts( async function * explicitReturnType3(): AsyncIterableIterator { yield* (async function * () { yield "a"; })(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '"a"' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. } async function * explicitReturnType4(): AsyncIterable { yield "a"; @@ -171,7 +153,7 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts( async function * explicitReturnType6(): AsyncIterable { yield* (async function * () { yield "a"; })(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '"a"' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. } async function * explicitReturnType7(): AsyncIterator { yield "a"; @@ -186,7 +168,7 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts( async function * explicitReturnType9(): AsyncIterator { yield* (async function * () { yield "a"; })(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '"a"' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. } async function * explicitReturnType10(): IterableIterator { ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/types.asyncGenerators.esnext.2.types b/tests/baselines/reference/types.asyncGenerators.esnext.2.types index 2d29f5a7e1d..c9f8e9216c4 100644 --- a/tests/baselines/reference/types.asyncGenerators.esnext.2.types +++ b/tests/baselines/reference/types.asyncGenerators.esnext.2.types @@ -30,7 +30,7 @@ async function * inferReturnType3() { const assignability1: () => AsyncIterableIterator = async function * () { >assignability1 : () => AsyncIterableIterator >AsyncIterableIterator : AsyncIterableIterator ->async function * () { yield "a";} : () => AsyncIterableIterator<"a"> +>async function * () { yield "a";} : () => AsyncIterableIterator yield "a"; >yield "a" : any @@ -52,13 +52,13 @@ const assignability2: () => AsyncIterableIterator = async function * () const assignability3: () => AsyncIterableIterator = async function * () { >assignability3 : () => AsyncIterableIterator >AsyncIterableIterator : AsyncIterableIterator ->async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncIterableIterator<"a"> +>async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncIterableIterator yield* (async function * () { yield "a"; })(); >yield* (async function * () { yield "a"; })() : any ->(async function * () { yield "a"; })() : AsyncIterableIterator<"a"> ->(async function * () { yield "a"; }) : () => AsyncIterableIterator<"a"> ->async function * () { yield "a"; } : () => AsyncIterableIterator<"a"> +>(async function * () { yield "a"; })() : AsyncIterableIterator +>(async function * () { yield "a"; }) : () => AsyncIterableIterator +>async function * () { yield "a"; } : () => AsyncIterableIterator >yield "a" : any >"a" : "a" @@ -66,7 +66,7 @@ const assignability3: () => AsyncIterableIterator = async function * () const assignability4: () => AsyncIterable = async function * () { >assignability4 : () => AsyncIterable >AsyncIterable : AsyncIterable ->async function * () { yield "a";} : () => AsyncIterableIterator<"a"> +>async function * () { yield "a";} : () => AsyncIterableIterator yield "a"; >yield "a" : any @@ -88,13 +88,13 @@ const assignability5: () => AsyncIterable = async function * () { const assignability6: () => AsyncIterable = async function * () { >assignability6 : () => AsyncIterable >AsyncIterable : AsyncIterable ->async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncIterableIterator<"a"> +>async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncIterableIterator yield* (async function * () { yield "a"; })(); >yield* (async function * () { yield "a"; })() : any ->(async function * () { yield "a"; })() : AsyncIterableIterator<"a"> ->(async function * () { yield "a"; }) : () => AsyncIterableIterator<"a"> ->async function * () { yield "a"; } : () => AsyncIterableIterator<"a"> +>(async function * () { yield "a"; })() : AsyncIterableIterator +>(async function * () { yield "a"; }) : () => AsyncIterableIterator +>async function * () { yield "a"; } : () => AsyncIterableIterator >yield "a" : any >"a" : "a" @@ -102,7 +102,7 @@ const assignability6: () => AsyncIterable = async function * () { const assignability7: () => AsyncIterator = async function * () { >assignability7 : () => AsyncIterator >AsyncIterator : AsyncIterator ->async function * () { yield "a";} : () => AsyncIterableIterator<"a"> +>async function * () { yield "a";} : () => AsyncIterableIterator yield "a"; >yield "a" : any @@ -124,13 +124,13 @@ const assignability8: () => AsyncIterator = async function * () { const assignability9: () => AsyncIterator = async function * () { >assignability9 : () => AsyncIterator >AsyncIterator : AsyncIterator ->async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncIterableIterator<"a"> +>async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncIterableIterator yield* (async function * () { yield "a"; })(); >yield* (async function * () { yield "a"; })() : any ->(async function * () { yield "a"; })() : AsyncIterableIterator<"a"> ->(async function * () { yield "a"; }) : () => AsyncIterableIterator<"a"> ->async function * () { yield "a"; } : () => AsyncIterableIterator<"a"> +>(async function * () { yield "a"; })() : AsyncIterableIterator +>(async function * () { yield "a"; }) : () => AsyncIterableIterator +>async function * () { yield "a"; } : () => AsyncIterableIterator >yield "a" : any >"a" : "a" @@ -159,9 +159,9 @@ async function * explicitReturnType3(): AsyncIterableIterator { yield* (async function * () { yield "a"; })(); >yield* (async function * () { yield "a"; })() : any ->(async function * () { yield "a"; })() : AsyncIterableIterator<"a"> ->(async function * () { yield "a"; }) : () => AsyncIterableIterator<"a"> ->async function * () { yield "a"; } : () => AsyncIterableIterator<"a"> +>(async function * () { yield "a"; })() : AsyncIterableIterator +>(async function * () { yield "a"; }) : () => AsyncIterableIterator +>async function * () { yield "a"; } : () => AsyncIterableIterator >yield "a" : any >"a" : "a" } @@ -189,9 +189,9 @@ async function * explicitReturnType6(): AsyncIterable { yield* (async function * () { yield "a"; })(); >yield* (async function * () { yield "a"; })() : any ->(async function * () { yield "a"; })() : AsyncIterableIterator<"a"> ->(async function * () { yield "a"; }) : () => AsyncIterableIterator<"a"> ->async function * () { yield "a"; } : () => AsyncIterableIterator<"a"> +>(async function * () { yield "a"; })() : AsyncIterableIterator +>(async function * () { yield "a"; }) : () => AsyncIterableIterator +>async function * () { yield "a"; } : () => AsyncIterableIterator >yield "a" : any >"a" : "a" } @@ -219,9 +219,9 @@ async function * explicitReturnType9(): AsyncIterator { yield* (async function * () { yield "a"; })(); >yield* (async function * () { yield "a"; })() : any ->(async function * () { yield "a"; })() : AsyncIterableIterator<"a"> ->(async function * () { yield "a"; }) : () => AsyncIterableIterator<"a"> ->async function * () { yield "a"; } : () => AsyncIterableIterator<"a"> +>(async function * () { yield "a"; })() : AsyncIterableIterator +>(async function * () { yield "a"; }) : () => AsyncIterableIterator +>async function * () { yield "a"; } : () => AsyncIterableIterator >yield "a" : any >"a" : "a" } diff --git a/tests/baselines/reference/uniqueSymbols.js b/tests/baselines/reference/uniqueSymbols.js index 4de307ee197..6c723c8dec1 100644 --- a/tests/baselines/reference/uniqueSymbols.js +++ b/tests/baselines/reference/uniqueSymbols.js @@ -122,6 +122,7 @@ declare function g(x: typeof s): void; declare function g(x: typeof N.s): void; // widening positions + // argument inference f(s); f(N.s); @@ -132,11 +133,17 @@ f(N["s"]); [N.s]; [N["s"]]; -// property assignments +// property assignments/methods const o2 = { a: s, b: N.s, - c: N["s"] + c: N["s"], + + method1() { return s; }, + async method2() { return s; }, + async * method3() { yield s; }, + * method4() { yield s; }, + method5(p = s) { return p; }, }; // property initializers @@ -156,6 +163,12 @@ class C0 { d = s; e = N.s; f = N["s"]; + + method1() { return s; } + async method2() { return s; } + async * method3() { yield s; } + * method4() { yield s; } + method5(p = s) { return p; } } // non-widening positions @@ -195,7 +208,60 @@ class C1 { [s]: "a"; [N.s]: "b"; -} +} + +// contextual types + +interface Context { + method1(): typeof s; + method2(): Promise; + method3(): AsyncIterableIterator; + method4(): IterableIterator; + method5(p?: typeof s): typeof s; +} + +const o3: Context = { + method1() { + return s; // return type should not widen due to contextual type + }, + async method2() { + return s; // return type should not widen due to contextual type + }, + async * method3() { + yield s; // yield type should not widen due to contextual type + }, + * method4() { + yield s; // yield type should not widen due to contextual type + }, + method5(p = s) { // parameter should not widen due to contextual type + return p; + }, +}; + +// allowed when not emitting declarations + +const o4 = { + method1(p: typeof s): typeof s { + return p; + }, + method2(p: I["readonlyType"]): I["readonlyType"] { + return p; + } +}; + +const ce0 = class { + method1(p: typeof s): typeof s { + return p; + } + method2(p: I["readonlyType"]): I["readonlyType"] { + return p; + } +}; + +function funcInferredReturnType(obj: { method(p: typeof s): void }) { + return obj; +} + //// [uniqueSymbols.js] // declarations with call initializer @@ -285,11 +351,16 @@ f(N["s"]); [s]; [N.s]; [N["s"]]; -// property assignments +// property assignments/methods const o2 = { a: s, b: N.s, - c: N["s"] + c: N["s"], + method1() { return s; }, + async method2() { return s; }, + async *method3() { yield s; }, + *method4() { yield s; }, + method5(p = s) { return p; }, }; // property initializers class C0 { @@ -301,6 +372,11 @@ class C0 { this.e = N.s; this.f = N["s"]; } + method1() { return s; } + async method2() { return s; } + async *method3() { yield s; } + *method4() { yield s; } + method5(p = s) { return p; } } C0.a = s; C0.b = N.s; @@ -335,120 +411,40 @@ Math.random() * 2 ? N["s"] : "a"; }); class C1 { } - - -//// [uniqueSymbols.d.ts] -declare const constCall: unique symbol; -declare let letCall: symbol; -declare var varCall: symbol; -declare const constType: unique symbol; -declare const constTypeAndCall: unique symbol; -declare const constInitToConstCall: symbol; -declare const constInitToLetCall: symbol; -declare const constInitToVarCall: symbol; -declare const constInitToConstDeclAmbient: symbol; -declare let letInitToConstCall: symbol; -declare let letInitToLetCall: symbol; -declare let letInitToVarCall: symbol; -declare let letInitToConstDeclAmbient: symbol; -declare var varInitToConstCall: symbol; -declare var varInitToLetCall: symbol; -declare var varInitToVarCall: symbol; -declare var varInitToConstDeclAmbient: symbol; -declare const constInitToConstCallWithTypeQuery: typeof constCall; -declare const constInitToConstDeclAmbientWithTypeQuery: typeof constType; -declare function funcReturnConstCall(): symbol; -declare function funcReturnLetCall(): symbol; -declare function funcReturnVarCall(): symbol; -declare function funcReturnConstCallWithTypeQuery(): typeof constCall; -declare function genFuncYieldConstCall(): IterableIterator; -declare function genFuncYieldLetCall(): IterableIterator; -declare function genFuncYieldVarCall(): IterableIterator; -declare function genFuncYieldConstCallWithTypeQuery(): IterableIterator; -declare function asyncFuncReturnConstCall(): Promise; -declare function asyncFuncReturnLetCall(): Promise; -declare function asyncFuncReturnVarCall(): Promise; -declare function asyncGenFuncYieldConstCall(): AsyncIterableIterator; -declare function asyncGenFuncYieldLetCall(): AsyncIterableIterator; -declare function asyncGenFuncYieldVarCall(): AsyncIterableIterator; -declare class C { - static readonly readonlyStaticCall: unique symbol; - static readonly readonlyStaticType: unique symbol; - static readonly readonlyStaticTypeAndCall: unique symbol; - static readwriteStaticCall: symbol; - readonly readonlyCall: symbol; - readwriteCall: symbol; -} -declare const c: C; -declare const constInitToCReadonlyStaticCall: symbol; -declare const constInitToCReadonlyStaticType: symbol; -declare const constInitToCReadonlyStaticTypeAndCall: symbol; -declare const constInitToCReadwriteStaticCall: symbol; -declare const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall; -declare const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType; -declare const constInitToCReadonlyStaticTypeAndCallWithTypeQuery: typeof C.readonlyStaticTypeAndCall; -declare const constInitToCReadwriteStaticCallWithTypeQuery: typeof C.readwriteStaticCall; -declare const constInitToCReadonlyCall: symbol; -declare const constInitToCReadwriteCall: symbol; -declare const constInitToCReadonlyCallWithTypeQuery: typeof c.readonlyCall; -declare const constInitToCReadwriteCallWithTypeQuery: typeof c.readwriteCall; -declare const constInitToCReadonlyCallWithIndexedAccess: C["readonlyCall"]; -declare const constInitToCReadwriteCallWithIndexedAccess: C["readwriteCall"]; -interface I { - readonly readonlyType: unique symbol; -} -declare const i: I; -declare const constInitToIReadonlyType: symbol; -declare const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType; -declare const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"]; -declare type L = { - readonly readonlyType: unique symbol; - nested: { - readonly readonlyNestedType: unique symbol; - }; +const o3 = { + method1() { + return s; // return type should not widen due to contextual type + }, + async method2() { + return s; // return type should not widen due to contextual type + }, + async *method3() { + yield s; // yield type should not widen due to contextual type + }, + *method4() { + yield s; // yield type should not widen due to contextual type + }, + method5(p = s) { + return p; + }, }; -declare const l: L; -declare const constInitToLReadonlyType: symbol; -declare const constInitToLReadonlyNestedType: symbol; -declare const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType; -declare const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType; -declare const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"]; -declare const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"]; -declare const promiseForConstCall: Promise; -declare const arrayOfConstCall: symbol[]; -declare const s: unique symbol; -declare namespace N { - const s: unique symbol; -} -declare const o: { - [s]: "a"; - [N.s]: "b"; +// allowed when not emitting declarations +const o4 = { + method1(p) { + return p; + }, + method2(p) { + return p; + } }; -declare function f(x: T): T; -declare function g(x: typeof s): void; -declare function g(x: typeof N.s): void; -declare const o2: { - a: symbol; - b: symbol; - c: symbol; +const ce0 = class { + method1(p) { + return p; + } + method2(p) { + return p; + } }; -declare class C0 { - static readonly a: symbol; - static readonly b: symbol; - static readonly c: symbol; - static d: symbol; - static e: symbol; - static f: symbol; - readonly a: symbol; - readonly b: symbol; - readonly c: symbol; - d: symbol; - e: symbol; - f: symbol; -} -declare class C1 { - static [s]: "a"; - static [N.s]: "b"; - [s]: "a"; - [N.s]: "b"; +function funcInferredReturnType(obj) { + return obj; } diff --git a/tests/baselines/reference/uniqueSymbols.symbols b/tests/baselines/reference/uniqueSymbols.symbols index 80c0611ce74..e798011683a 100644 --- a/tests/baselines/reference/uniqueSymbols.symbols +++ b/tests/baselines/reference/uniqueSymbols.symbols @@ -431,6 +431,7 @@ declare function g(x: typeof N.s): void; >s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) // widening positions + // argument inference f(s); >f : Symbol(f, Decl(uniqueSymbols.ts, 117, 42)) @@ -460,90 +461,134 @@ f(N["s"]); >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) -// property assignments +// property assignments/methods const o2 = { ->o2 : Symbol(o2, Decl(uniqueSymbols.ts, 134, 5)) +>o2 : Symbol(o2, Decl(uniqueSymbols.ts, 135, 5)) a: s, ->a : Symbol(a, Decl(uniqueSymbols.ts, 134, 12)) +>a : Symbol(a, Decl(uniqueSymbols.ts, 135, 12)) >s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) b: N.s, ->b : Symbol(b, Decl(uniqueSymbols.ts, 135, 9)) +>b : Symbol(b, Decl(uniqueSymbols.ts, 136, 9)) >N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) - c: N["s"] ->c : Symbol(c, Decl(uniqueSymbols.ts, 136, 11)) + c: N["s"], +>c : Symbol(c, Decl(uniqueSymbols.ts, 137, 11)) >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) + method1() { return s; }, +>method1 : Symbol(method1, Decl(uniqueSymbols.ts, 138, 14)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + async method2() { return s; }, +>method2 : Symbol(method2, Decl(uniqueSymbols.ts, 140, 28)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + async * method3() { yield s; }, +>method3 : Symbol(method3, Decl(uniqueSymbols.ts, 141, 34)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + * method4() { yield s; }, +>method4 : Symbol(method4, Decl(uniqueSymbols.ts, 142, 35)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + method5(p = s) { return p; }, +>method5 : Symbol(method5, Decl(uniqueSymbols.ts, 143, 29)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 144, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 144, 12)) + }; // property initializers class C0 { ->C0 : Symbol(C0, Decl(uniqueSymbols.ts, 138, 2)) +>C0 : Symbol(C0, Decl(uniqueSymbols.ts, 145, 2)) static readonly a = s; ->a : Symbol(C0.a, Decl(uniqueSymbols.ts, 141, 10)) +>a : Symbol(C0.a, Decl(uniqueSymbols.ts, 148, 10)) >s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) static readonly b = N.s; ->b : Symbol(C0.b, Decl(uniqueSymbols.ts, 142, 26)) +>b : Symbol(C0.b, Decl(uniqueSymbols.ts, 149, 26)) >N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) static readonly c = N["s"]; ->c : Symbol(C0.c, Decl(uniqueSymbols.ts, 143, 28)) +>c : Symbol(C0.c, Decl(uniqueSymbols.ts, 150, 28)) >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) static d = s; ->d : Symbol(C0.d, Decl(uniqueSymbols.ts, 144, 31)) +>d : Symbol(C0.d, Decl(uniqueSymbols.ts, 151, 31)) >s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) static e = N.s; ->e : Symbol(C0.e, Decl(uniqueSymbols.ts, 146, 17)) +>e : Symbol(C0.e, Decl(uniqueSymbols.ts, 153, 17)) >N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) static f = N["s"]; ->f : Symbol(C0.f, Decl(uniqueSymbols.ts, 147, 19)) +>f : Symbol(C0.f, Decl(uniqueSymbols.ts, 154, 19)) >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) readonly a = s; ->a : Symbol(C0.a, Decl(uniqueSymbols.ts, 148, 22)) +>a : Symbol(C0.a, Decl(uniqueSymbols.ts, 155, 22)) >s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) readonly b = N.s; ->b : Symbol(C0.b, Decl(uniqueSymbols.ts, 150, 19)) +>b : Symbol(C0.b, Decl(uniqueSymbols.ts, 157, 19)) >N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) readonly c = N["s"]; ->c : Symbol(C0.c, Decl(uniqueSymbols.ts, 151, 21)) +>c : Symbol(C0.c, Decl(uniqueSymbols.ts, 158, 21)) >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) d = s; ->d : Symbol(C0.d, Decl(uniqueSymbols.ts, 152, 24)) +>d : Symbol(C0.d, Decl(uniqueSymbols.ts, 159, 24)) >s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) e = N.s; ->e : Symbol(C0.e, Decl(uniqueSymbols.ts, 154, 10)) +>e : Symbol(C0.e, Decl(uniqueSymbols.ts, 161, 10)) >N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) f = N["s"]; ->f : Symbol(C0.f, Decl(uniqueSymbols.ts, 155, 12)) +>f : Symbol(C0.f, Decl(uniqueSymbols.ts, 162, 12)) >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) + + method1() { return s; } +>method1 : Symbol(C0.method1, Decl(uniqueSymbols.ts, 163, 15)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + async method2() { return s; } +>method2 : Symbol(C0.method2, Decl(uniqueSymbols.ts, 165, 27)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + async * method3() { yield s; } +>method3 : Symbol(C0.method3, Decl(uniqueSymbols.ts, 166, 33)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + * method4() { yield s; } +>method4 : Symbol(C0.method4, Decl(uniqueSymbols.ts, 167, 34)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + method5(p = s) { return p; } +>method5 : Symbol(C0.method5, Decl(uniqueSymbols.ts, 168, 28)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 169, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 169, 12)) } // non-widening positions @@ -650,7 +695,7 @@ Math.random() * 2 ? N["s"] : "a"; }); class C1 { ->C1 : Symbol(C1, Decl(uniqueSymbols.ts, 188, 3)) +>C1 : Symbol(C1, Decl(uniqueSymbols.ts, 201, 3)) static [s]: "a"; >s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) @@ -668,3 +713,138 @@ class C1 { >N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) >s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) } + +// contextual types + +interface Context { +>Context : Symbol(Context, Decl(uniqueSymbols.ts, 209, 1)) + + method1(): typeof s; +>method1 : Symbol(Context.method1, Decl(uniqueSymbols.ts, 213, 19)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + method2(): Promise; +>method2 : Symbol(Context.method2, Decl(uniqueSymbols.ts, 214, 24)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + method3(): AsyncIterableIterator; +>method3 : Symbol(Context.method3, Decl(uniqueSymbols.ts, 215, 33)) +>AsyncIterableIterator : Symbol(AsyncIterableIterator, Decl(lib.esnext.asynciterable.d.ts, --, --)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + method4(): IterableIterator; +>method4 : Symbol(Context.method4, Decl(uniqueSymbols.ts, 216, 47)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.es2015.iterable.d.ts, --, --)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + method5(p?: typeof s): typeof s; +>method5 : Symbol(Context.method5, Decl(uniqueSymbols.ts, 217, 42)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 218, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +} + +const o3: Context = { +>o3 : Symbol(o3, Decl(uniqueSymbols.ts, 221, 5)) +>Context : Symbol(Context, Decl(uniqueSymbols.ts, 209, 1)) + + method1() { +>method1 : Symbol(method1, Decl(uniqueSymbols.ts, 221, 21)) + + return s; // return type should not widen due to contextual type +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + }, + async method2() { +>method2 : Symbol(method2, Decl(uniqueSymbols.ts, 224, 6)) + + return s; // return type should not widen due to contextual type +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + }, + async * method3() { +>method3 : Symbol(method3, Decl(uniqueSymbols.ts, 227, 6)) + + yield s; // yield type should not widen due to contextual type +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + }, + * method4() { +>method4 : Symbol(method4, Decl(uniqueSymbols.ts, 230, 6)) + + yield s; // yield type should not widen due to contextual type +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + }, + method5(p = s) { // parameter should not widen due to contextual type +>method5 : Symbol(method5, Decl(uniqueSymbols.ts, 233, 6)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 234, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + return p; +>p : Symbol(p, Decl(uniqueSymbols.ts, 234, 12)) + + }, +}; + +// allowed when not emitting declarations + +const o4 = { +>o4 : Symbol(o4, Decl(uniqueSymbols.ts, 241, 5)) + + method1(p: typeof s): typeof s { +>method1 : Symbol(method1, Decl(uniqueSymbols.ts, 241, 12)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 242, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + return p; +>p : Symbol(p, Decl(uniqueSymbols.ts, 242, 12)) + + }, + method2(p: I["readonlyType"]): I["readonlyType"] { +>method2 : Symbol(method2, Decl(uniqueSymbols.ts, 244, 6)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 245, 12)) +>I : Symbol(I, Decl(uniqueSymbols.ts, 82, 87)) +>I : Symbol(I, Decl(uniqueSymbols.ts, 82, 87)) + + return p; +>p : Symbol(p, Decl(uniqueSymbols.ts, 245, 12)) + } +}; + +const ce0 = class { +>ce0 : Symbol(ce0, Decl(uniqueSymbols.ts, 250, 5)) + + method1(p: typeof s): typeof s { +>method1 : Symbol(ce0.method1, Decl(uniqueSymbols.ts, 250, 19)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 251, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + return p; +>p : Symbol(p, Decl(uniqueSymbols.ts, 251, 12)) + } + method2(p: I["readonlyType"]): I["readonlyType"] { +>method2 : Symbol(ce0.method2, Decl(uniqueSymbols.ts, 253, 5)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 254, 12)) +>I : Symbol(I, Decl(uniqueSymbols.ts, 82, 87)) +>I : Symbol(I, Decl(uniqueSymbols.ts, 82, 87)) + + return p; +>p : Symbol(p, Decl(uniqueSymbols.ts, 254, 12)) + } +}; + +function funcInferredReturnType(obj: { method(p: typeof s): void }) { +>funcInferredReturnType : Symbol(funcInferredReturnType, Decl(uniqueSymbols.ts, 257, 2)) +>obj : Symbol(obj, Decl(uniqueSymbols.ts, 259, 32)) +>method : Symbol(method, Decl(uniqueSymbols.ts, 259, 38)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 259, 46)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) + + return obj; +>obj : Symbol(obj, Decl(uniqueSymbols.ts, 259, 32)) +} + diff --git a/tests/baselines/reference/uniqueSymbols.types b/tests/baselines/reference/uniqueSymbols.types index 3deaf4572f4..6516ee25dd0 100644 --- a/tests/baselines/reference/uniqueSymbols.types +++ b/tests/baselines/reference/uniqueSymbols.types @@ -449,6 +449,7 @@ declare function g(x: typeof N.s): void; >s : unique symbol // widening positions + // argument inference f(s); >f(s) : symbol @@ -486,10 +487,10 @@ f(N["s"]); >N : typeof N >"s" : "s" -// property assignments +// property assignments/methods const o2 = { ->o2 : { a: symbol; b: symbol; c: symbol; } ->{ a: s, b: N.s, c: N["s"]} : { a: symbol; b: symbol; c: symbol; } +>o2 : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncIterableIterator; method4(): IterableIterator; method5(p?: symbol): symbol; } +>{ a: s, b: N.s, c: N["s"], method1() { return s; }, async method2() { return s; }, async * method3() { yield s; }, * method4() { yield s; }, method5(p = s) { return p; },} : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncIterableIterator; method4(): IterableIterator; method5(p?: symbol): symbol; } a: s, >a : symbol @@ -501,12 +502,36 @@ const o2 = { >N : typeof N >s : unique symbol - c: N["s"] + c: N["s"], >c : symbol >N["s"] : unique symbol >N : typeof N >"s" : "s" + method1() { return s; }, +>method1 : () => symbol +>s : unique symbol + + async method2() { return s; }, +>method2 : () => Promise +>s : unique symbol + + async * method3() { yield s; }, +>method3 : () => AsyncIterableIterator +>yield s : any +>s : unique symbol + + * method4() { yield s; }, +>method4 : () => IterableIterator +>yield s : any +>s : unique symbol + + method5(p = s) { return p; }, +>method5 : (p?: symbol) => symbol +>p : symbol +>s : unique symbol +>p : symbol + }; // property initializers @@ -576,6 +601,30 @@ class C0 { >N["s"] : unique symbol >N : typeof N >"s" : "s" + + method1() { return s; } +>method1 : () => symbol +>s : unique symbol + + async method2() { return s; } +>method2 : () => Promise +>s : unique symbol + + async * method3() { yield s; } +>method3 : () => AsyncIterableIterator +>yield s : any +>s : unique symbol + + * method4() { yield s; } +>method4 : () => IterableIterator +>yield s : any +>s : unique symbol + + method5(p = s) { return p; } +>method5 : (p?: symbol) => symbol +>p : symbol +>s : unique symbol +>p : symbol } // non-widening positions @@ -740,3 +789,143 @@ class C1 { >N : typeof N >s : unique symbol } + +// contextual types + +interface Context { +>Context : Context + + method1(): typeof s; +>method1 : () => unique symbol +>s : unique symbol + + method2(): Promise; +>method2 : () => Promise +>Promise : Promise +>s : unique symbol + + method3(): AsyncIterableIterator; +>method3 : () => AsyncIterableIterator +>AsyncIterableIterator : AsyncIterableIterator +>s : unique symbol + + method4(): IterableIterator; +>method4 : () => IterableIterator +>IterableIterator : IterableIterator +>s : unique symbol + + method5(p?: typeof s): typeof s; +>method5 : (p?: unique symbol) => unique symbol +>p : unique symbol +>s : unique symbol +>s : unique symbol +} + +const o3: Context = { +>o3 : Context +>Context : Context +>{ method1() { return s; // return type should not widen due to contextual type }, async method2() { return s; // return type should not widen due to contextual type }, async * method3() { yield s; // yield type should not widen due to contextual type }, * method4() { yield s; // yield type should not widen due to contextual type }, method5(p = s) { // parameter should not widen due to contextual type return p; },} : { method1(): unique symbol; method2(): Promise; method3(): AsyncIterableIterator; method4(): IterableIterator; method5(p?: unique symbol): unique symbol; } + + method1() { +>method1 : () => unique symbol + + return s; // return type should not widen due to contextual type +>s : unique symbol + + }, + async method2() { +>method2 : () => Promise + + return s; // return type should not widen due to contextual type +>s : unique symbol + + }, + async * method3() { +>method3 : () => AsyncIterableIterator + + yield s; // yield type should not widen due to contextual type +>yield s : any +>s : unique symbol + + }, + * method4() { +>method4 : () => IterableIterator + + yield s; // yield type should not widen due to contextual type +>yield s : any +>s : unique symbol + + }, + method5(p = s) { // parameter should not widen due to contextual type +>method5 : (p?: unique symbol) => unique symbol +>p : unique symbol +>s : unique symbol + + return p; +>p : unique symbol + + }, +}; + +// allowed when not emitting declarations + +const o4 = { +>o4 : { method1(p: unique symbol): unique symbol; method2(p: unique symbol): unique symbol; } +>{ method1(p: typeof s): typeof s { return p; }, method2(p: I["readonlyType"]): I["readonlyType"] { return p; }} : { method1(p: unique symbol): unique symbol; method2(p: unique symbol): unique symbol; } + + method1(p: typeof s): typeof s { +>method1 : (p: unique symbol) => unique symbol +>p : unique symbol +>s : unique symbol +>s : unique symbol + + return p; +>p : unique symbol + + }, + method2(p: I["readonlyType"]): I["readonlyType"] { +>method2 : (p: unique symbol) => unique symbol +>p : unique symbol +>I : I +>I : I + + return p; +>p : unique symbol + } +}; + +const ce0 = class { +>ce0 : typeof ce0 +>class { method1(p: typeof s): typeof s { return p; } method2(p: I["readonlyType"]): I["readonlyType"] { return p; }} : typeof ce0 + + method1(p: typeof s): typeof s { +>method1 : (p: unique symbol) => unique symbol +>p : unique symbol +>s : unique symbol +>s : unique symbol + + return p; +>p : unique symbol + } + method2(p: I["readonlyType"]): I["readonlyType"] { +>method2 : (p: unique symbol) => unique symbol +>p : unique symbol +>I : I +>I : I + + return p; +>p : unique symbol + } +}; + +function funcInferredReturnType(obj: { method(p: typeof s): void }) { +>funcInferredReturnType : (obj: { method(p: unique symbol): void; }) => { method(p: unique symbol): void; } +>obj : { method(p: unique symbol): void; } +>method : (p: unique symbol) => void +>p : unique symbol +>s : unique symbol + + return obj; +>obj : { method(p: unique symbol): void; } +} + diff --git a/tests/baselines/reference/uniqueSymbolsDeclarations.js b/tests/baselines/reference/uniqueSymbolsDeclarations.js new file mode 100644 index 00000000000..6b52b210977 --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarations.js @@ -0,0 +1,540 @@ +//// [uniqueSymbolsDeclarations.ts] +// declarations with call initializer +const constCall = Symbol(); +let letCall = Symbol(); +var varCall = Symbol(); + +// ambient declaration with type +declare const constType: unique symbol; + +// declaration with type and call initializer +const constTypeAndCall: unique symbol = Symbol(); + +// declaration from initializer +const constInitToConstCall = constCall; +const constInitToLetCall = letCall; +const constInitToVarCall = varCall; +const constInitToConstDeclAmbient = constType; +let letInitToConstCall = constCall; +let letInitToLetCall = letCall; +let letInitToVarCall = varCall; +let letInitToConstDeclAmbient = constType; +var varInitToConstCall = constCall; +var varInitToLetCall = letCall; +var varInitToVarCall = varCall; +var varInitToConstDeclAmbient = constType; + +// declaration from initializer with type query +const constInitToConstCallWithTypeQuery: typeof constCall = constCall; +const constInitToConstDeclAmbientWithTypeQuery: typeof constType = constType; + +// function return inference +function funcReturnConstCall() { return constCall; } +function funcReturnLetCall() { return letCall; } +function funcReturnVarCall() { return varCall; } + +// function return value with type query +function funcReturnConstCallWithTypeQuery(): typeof constCall { return constCall; } + +// generator function yield inference +function* genFuncYieldConstCall() { yield constCall; } +function* genFuncYieldLetCall() { yield letCall; } +function* genFuncYieldVarCall() { yield varCall; } + +// generator function yield with return type query +function* genFuncYieldConstCallWithTypeQuery(): IterableIterator { yield constCall; } + +// async function return inference +async function asyncFuncReturnConstCall() { return constCall; } +async function asyncFuncReturnLetCall() { return letCall; } +async function asyncFuncReturnVarCall() { return varCall; } + +// async generator function yield inference +async function* asyncGenFuncYieldConstCall() { yield constCall; } +async function* asyncGenFuncYieldLetCall() { yield letCall; } +async function* asyncGenFuncYieldVarCall() { yield varCall; } + +// classes +class C { + static readonly readonlyStaticCall = Symbol(); + static readonly readonlyStaticType: unique symbol; + static readonly readonlyStaticTypeAndCall: unique symbol = Symbol(); + static readwriteStaticCall = Symbol(); + + readonly readonlyCall = Symbol(); + readwriteCall = Symbol(); +} +declare const c: C; + +const constInitToCReadonlyStaticCall = C.readonlyStaticCall; +const constInitToCReadonlyStaticType = C.readonlyStaticType; +const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; +const constInitToCReadwriteStaticCall = C.readwriteStaticCall; + +const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall = C.readonlyStaticCall; +const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType = C.readonlyStaticType; +const constInitToCReadonlyStaticTypeAndCallWithTypeQuery: typeof C.readonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; +const constInitToCReadwriteStaticCallWithTypeQuery: typeof C.readwriteStaticCall = C.readwriteStaticCall; + +const constInitToCReadonlyCall = c.readonlyCall; +const constInitToCReadwriteCall = c.readwriteCall; +const constInitToCReadonlyCallWithTypeQuery: typeof c.readonlyCall = c.readonlyCall; +const constInitToCReadwriteCallWithTypeQuery: typeof c.readwriteCall = c.readwriteCall; +const constInitToCReadonlyCallWithIndexedAccess: C["readonlyCall"] = c.readonlyCall; +const constInitToCReadwriteCallWithIndexedAccess: C["readwriteCall"] = c.readwriteCall; + +// interfaces +interface I { + readonly readonlyType: unique symbol; +} +declare const i: I; + +const constInitToIReadonlyType = i.readonlyType; +const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType = i.readonlyType; +const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"] = i.readonlyType; + +// type literals +type L = { + readonly readonlyType: unique symbol; + nested: { + readonly readonlyNestedType: unique symbol; + } +}; +declare const l: L; + +const constInitToLReadonlyType = l.readonlyType; +const constInitToLReadonlyNestedType = l.nested.readonlyNestedType; +const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType = l.readonlyType; +const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType = l.nested.readonlyNestedType; +const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"] = l.readonlyType; +const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"] = l.nested.readonlyNestedType; + +// type argument inference +const promiseForConstCall = Promise.resolve(constCall); +const arrayOfConstCall = [constCall]; + +// unique symbol widening in expressions +declare const s: unique symbol; +declare namespace N { const s: unique symbol; } +declare const o: { [s]: "a", [N.s]: "b" }; +declare function f(x: T): T; +declare function g(x: typeof s): void; +declare function g(x: typeof N.s): void; + +// widening positions + +// argument inference +f(s); +f(N.s); +f(N["s"]); + +// array literal elements +[s]; +[N.s]; +[N["s"]]; + +// property assignments/methods +const o2 = { + a: s, + b: N.s, + c: N["s"], + + method1() { return s; }, + async method2() { return s; }, + async * method3() { yield s; }, + * method4() { yield s; }, + method5(p = s) { return p; } +}; + +// property initializers +class C0 { + static readonly a = s; + static readonly b = N.s; + static readonly c = N["s"]; + + static d = s; + static e = N.s; + static f = N["s"]; + + readonly a = s; + readonly b = N.s; + readonly c = N["s"]; + + d = s; + e = N.s; + f = N["s"]; + + method1() { return s; } + async method2() { return s; } + async * method3() { yield s; } + * method4() { yield s; } + method5(p = s) { return p; } +} + +// non-widening positions + +// element access +o[s]; +o[N.s]; +o[N["s"]]; + +// arguments (no-inference) +f(s); +f(N.s); +f(N["s"]); +g(s); +g(N.s); +g(N["s"]); + +// falsy expressions +s || ""; +N.s || ""; +N["s"] || ""; + +// conditionals +Math.random() * 2 ? s : "a"; +Math.random() * 2 ? N.s : "a"; +Math.random() * 2 ? N["s"] : "a"; + +// computed property names +({ + [s]: "a", + [N.s]: "b", +}); + +class C1 { + static [s]: "a"; + static [N.s]: "b"; + + [s]: "a"; + [N.s]: "b"; +} + +// contextual types + +interface Context { + method1(): typeof s; + method2(): Promise; + method3(): AsyncIterableIterator; + method4(): IterableIterator; + method5(p?: typeof s): typeof s; +} + +const o4: Context = { + method1() { + return s; // return type should not widen due to contextual type + }, + async method2() { + return s; // return type should not widen due to contextual type + }, + async * method3() { + yield s; // yield type should not widen due to contextual type + }, + * method4() { + yield s; // yield type should not widen due to contextual type + }, + method5(p = s) { // parameter should not widen due to contextual type + return p; + } +}; + +//// [uniqueSymbolsDeclarations.js] +// declarations with call initializer +const constCall = Symbol(); +let letCall = Symbol(); +var varCall = Symbol(); +// declaration with type and call initializer +const constTypeAndCall = Symbol(); +// declaration from initializer +const constInitToConstCall = constCall; +const constInitToLetCall = letCall; +const constInitToVarCall = varCall; +const constInitToConstDeclAmbient = constType; +let letInitToConstCall = constCall; +let letInitToLetCall = letCall; +let letInitToVarCall = varCall; +let letInitToConstDeclAmbient = constType; +var varInitToConstCall = constCall; +var varInitToLetCall = letCall; +var varInitToVarCall = varCall; +var varInitToConstDeclAmbient = constType; +// declaration from initializer with type query +const constInitToConstCallWithTypeQuery = constCall; +const constInitToConstDeclAmbientWithTypeQuery = constType; +// function return inference +function funcReturnConstCall() { return constCall; } +function funcReturnLetCall() { return letCall; } +function funcReturnVarCall() { return varCall; } +// function return value with type query +function funcReturnConstCallWithTypeQuery() { return constCall; } +// generator function yield inference +function* genFuncYieldConstCall() { yield constCall; } +function* genFuncYieldLetCall() { yield letCall; } +function* genFuncYieldVarCall() { yield varCall; } +// generator function yield with return type query +function* genFuncYieldConstCallWithTypeQuery() { yield constCall; } +// async function return inference +async function asyncFuncReturnConstCall() { return constCall; } +async function asyncFuncReturnLetCall() { return letCall; } +async function asyncFuncReturnVarCall() { return varCall; } +// async generator function yield inference +async function* asyncGenFuncYieldConstCall() { yield constCall; } +async function* asyncGenFuncYieldLetCall() { yield letCall; } +async function* asyncGenFuncYieldVarCall() { yield varCall; } +// classes +class C { + constructor() { + this.readonlyCall = Symbol(); + this.readwriteCall = Symbol(); + } +} +C.readonlyStaticCall = Symbol(); +C.readonlyStaticTypeAndCall = Symbol(); +C.readwriteStaticCall = Symbol(); +const constInitToCReadonlyStaticCall = C.readonlyStaticCall; +const constInitToCReadonlyStaticType = C.readonlyStaticType; +const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; +const constInitToCReadwriteStaticCall = C.readwriteStaticCall; +const constInitToCReadonlyStaticCallWithTypeQuery = C.readonlyStaticCall; +const constInitToCReadonlyStaticTypeWithTypeQuery = C.readonlyStaticType; +const constInitToCReadonlyStaticTypeAndCallWithTypeQuery = C.readonlyStaticTypeAndCall; +const constInitToCReadwriteStaticCallWithTypeQuery = C.readwriteStaticCall; +const constInitToCReadonlyCall = c.readonlyCall; +const constInitToCReadwriteCall = c.readwriteCall; +const constInitToCReadonlyCallWithTypeQuery = c.readonlyCall; +const constInitToCReadwriteCallWithTypeQuery = c.readwriteCall; +const constInitToCReadonlyCallWithIndexedAccess = c.readonlyCall; +const constInitToCReadwriteCallWithIndexedAccess = c.readwriteCall; +const constInitToIReadonlyType = i.readonlyType; +const constInitToIReadonlyTypeWithTypeQuery = i.readonlyType; +const constInitToIReadonlyTypeWithIndexedAccess = i.readonlyType; +const constInitToLReadonlyType = l.readonlyType; +const constInitToLReadonlyNestedType = l.nested.readonlyNestedType; +const constInitToLReadonlyTypeWithTypeQuery = l.readonlyType; +const constInitToLReadonlyNestedTypeWithTypeQuery = l.nested.readonlyNestedType; +const constInitToLReadonlyTypeWithIndexedAccess = l.readonlyType; +const constInitToLReadonlyNestedTypeWithIndexedAccess = l.nested.readonlyNestedType; +// type argument inference +const promiseForConstCall = Promise.resolve(constCall); +const arrayOfConstCall = [constCall]; +// widening positions +// argument inference +f(s); +f(N.s); +f(N["s"]); +// array literal elements +[s]; +[N.s]; +[N["s"]]; +// property assignments/methods +const o2 = { + a: s, + b: N.s, + c: N["s"], + method1() { return s; }, + async method2() { return s; }, + async *method3() { yield s; }, + *method4() { yield s; }, + method5(p = s) { return p; } +}; +// property initializers +class C0 { + constructor() { + this.a = s; + this.b = N.s; + this.c = N["s"]; + this.d = s; + this.e = N.s; + this.f = N["s"]; + } + method1() { return s; } + async method2() { return s; } + async *method3() { yield s; } + *method4() { yield s; } + method5(p = s) { return p; } +} +C0.a = s; +C0.b = N.s; +C0.c = N["s"]; +C0.d = s; +C0.e = N.s; +C0.f = N["s"]; +// non-widening positions +// element access +o[s]; +o[N.s]; +o[N["s"]]; +// arguments (no-inference) +f(s); +f(N.s); +f(N["s"]); +g(s); +g(N.s); +g(N["s"]); +// falsy expressions +s || ""; +N.s || ""; +N["s"] || ""; +// conditionals +Math.random() * 2 ? s : "a"; +Math.random() * 2 ? N.s : "a"; +Math.random() * 2 ? N["s"] : "a"; +// computed property names +({ + [s]: "a", + [N.s]: "b", +}); +class C1 { +} +const o4 = { + method1() { + return s; // return type should not widen due to contextual type + }, + async method2() { + return s; // return type should not widen due to contextual type + }, + async *method3() { + yield s; // yield type should not widen due to contextual type + }, + *method4() { + yield s; // yield type should not widen due to contextual type + }, + method5(p = s) { + return p; + } +}; + + +//// [uniqueSymbolsDeclarations.d.ts] +declare const constCall: unique symbol; +declare let letCall: symbol; +declare var varCall: symbol; +declare const constType: unique symbol; +declare const constTypeAndCall: unique symbol; +declare const constInitToConstCall: symbol; +declare const constInitToLetCall: symbol; +declare const constInitToVarCall: symbol; +declare const constInitToConstDeclAmbient: symbol; +declare let letInitToConstCall: symbol; +declare let letInitToLetCall: symbol; +declare let letInitToVarCall: symbol; +declare let letInitToConstDeclAmbient: symbol; +declare var varInitToConstCall: symbol; +declare var varInitToLetCall: symbol; +declare var varInitToVarCall: symbol; +declare var varInitToConstDeclAmbient: symbol; +declare const constInitToConstCallWithTypeQuery: typeof constCall; +declare const constInitToConstDeclAmbientWithTypeQuery: typeof constType; +declare function funcReturnConstCall(): symbol; +declare function funcReturnLetCall(): symbol; +declare function funcReturnVarCall(): symbol; +declare function funcReturnConstCallWithTypeQuery(): typeof constCall; +declare function genFuncYieldConstCall(): IterableIterator; +declare function genFuncYieldLetCall(): IterableIterator; +declare function genFuncYieldVarCall(): IterableIterator; +declare function genFuncYieldConstCallWithTypeQuery(): IterableIterator; +declare function asyncFuncReturnConstCall(): Promise; +declare function asyncFuncReturnLetCall(): Promise; +declare function asyncFuncReturnVarCall(): Promise; +declare function asyncGenFuncYieldConstCall(): AsyncIterableIterator; +declare function asyncGenFuncYieldLetCall(): AsyncIterableIterator; +declare function asyncGenFuncYieldVarCall(): AsyncIterableIterator; +declare class C { + static readonly readonlyStaticCall: unique symbol; + static readonly readonlyStaticType: unique symbol; + static readonly readonlyStaticTypeAndCall: unique symbol; + static readwriteStaticCall: symbol; + readonly readonlyCall: symbol; + readwriteCall: symbol; +} +declare const c: C; +declare const constInitToCReadonlyStaticCall: symbol; +declare const constInitToCReadonlyStaticType: symbol; +declare const constInitToCReadonlyStaticTypeAndCall: symbol; +declare const constInitToCReadwriteStaticCall: symbol; +declare const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall; +declare const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType; +declare const constInitToCReadonlyStaticTypeAndCallWithTypeQuery: typeof C.readonlyStaticTypeAndCall; +declare const constInitToCReadwriteStaticCallWithTypeQuery: typeof C.readwriteStaticCall; +declare const constInitToCReadonlyCall: symbol; +declare const constInitToCReadwriteCall: symbol; +declare const constInitToCReadonlyCallWithTypeQuery: typeof c.readonlyCall; +declare const constInitToCReadwriteCallWithTypeQuery: typeof c.readwriteCall; +declare const constInitToCReadonlyCallWithIndexedAccess: C["readonlyCall"]; +declare const constInitToCReadwriteCallWithIndexedAccess: C["readwriteCall"]; +interface I { + readonly readonlyType: unique symbol; +} +declare const i: I; +declare const constInitToIReadonlyType: symbol; +declare const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType; +declare const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"]; +declare type L = { + readonly readonlyType: unique symbol; + nested: { + readonly readonlyNestedType: unique symbol; + }; +}; +declare const l: L; +declare const constInitToLReadonlyType: symbol; +declare const constInitToLReadonlyNestedType: symbol; +declare const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType; +declare const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType; +declare const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"]; +declare const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"]; +declare const promiseForConstCall: Promise; +declare const arrayOfConstCall: symbol[]; +declare const s: unique symbol; +declare namespace N { + const s: unique symbol; +} +declare const o: { + [s]: "a"; + [N.s]: "b"; +}; +declare function f(x: T): T; +declare function g(x: typeof s): void; +declare function g(x: typeof N.s): void; +declare const o2: { + a: symbol; + b: symbol; + c: symbol; + method1(): symbol; + method2(): Promise; + method3(): AsyncIterableIterator; + method4(): IterableIterator; + method5(p?: symbol): symbol; +}; +declare class C0 { + static readonly a: symbol; + static readonly b: symbol; + static readonly c: symbol; + static d: symbol; + static e: symbol; + static f: symbol; + readonly a: symbol; + readonly b: symbol; + readonly c: symbol; + d: symbol; + e: symbol; + f: symbol; + method1(): symbol; + method2(): Promise; + method3(): AsyncIterableIterator; + method4(): IterableIterator; + method5(p?: symbol): symbol; +} +declare class C1 { + static [s]: "a"; + static [N.s]: "b"; + [s]: "a"; + [N.s]: "b"; +} +interface Context { + method1(): typeof s; + method2(): Promise; + method3(): AsyncIterableIterator; + method4(): IterableIterator; + method5(p?: typeof s): typeof s; +} +declare const o4: Context; diff --git a/tests/baselines/reference/uniqueSymbolsDeclarations.symbols b/tests/baselines/reference/uniqueSymbolsDeclarations.symbols new file mode 100644 index 00000000000..ff433aa19d0 --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarations.symbols @@ -0,0 +1,788 @@ +=== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarations.ts === +// declarations with call initializer +const constCall = Symbol(); +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + +let letCall = Symbol(); +>letCall : Symbol(letCall, Decl(uniqueSymbolsDeclarations.ts, 2, 3)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + +var varCall = Symbol(); +>varCall : Symbol(varCall, Decl(uniqueSymbolsDeclarations.ts, 3, 3)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + +// ambient declaration with type +declare const constType: unique symbol; +>constType : Symbol(constType, Decl(uniqueSymbolsDeclarations.ts, 6, 13)) + +// declaration with type and call initializer +const constTypeAndCall: unique symbol = Symbol(); +>constTypeAndCall : Symbol(constTypeAndCall, Decl(uniqueSymbolsDeclarations.ts, 9, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + +// declaration from initializer +const constInitToConstCall = constCall; +>constInitToConstCall : Symbol(constInitToConstCall, Decl(uniqueSymbolsDeclarations.ts, 12, 5)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +const constInitToLetCall = letCall; +>constInitToLetCall : Symbol(constInitToLetCall, Decl(uniqueSymbolsDeclarations.ts, 13, 5)) +>letCall : Symbol(letCall, Decl(uniqueSymbolsDeclarations.ts, 2, 3)) + +const constInitToVarCall = varCall; +>constInitToVarCall : Symbol(constInitToVarCall, Decl(uniqueSymbolsDeclarations.ts, 14, 5)) +>varCall : Symbol(varCall, Decl(uniqueSymbolsDeclarations.ts, 3, 3)) + +const constInitToConstDeclAmbient = constType; +>constInitToConstDeclAmbient : Symbol(constInitToConstDeclAmbient, Decl(uniqueSymbolsDeclarations.ts, 15, 5)) +>constType : Symbol(constType, Decl(uniqueSymbolsDeclarations.ts, 6, 13)) + +let letInitToConstCall = constCall; +>letInitToConstCall : Symbol(letInitToConstCall, Decl(uniqueSymbolsDeclarations.ts, 16, 3)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +let letInitToLetCall = letCall; +>letInitToLetCall : Symbol(letInitToLetCall, Decl(uniqueSymbolsDeclarations.ts, 17, 3)) +>letCall : Symbol(letCall, Decl(uniqueSymbolsDeclarations.ts, 2, 3)) + +let letInitToVarCall = varCall; +>letInitToVarCall : Symbol(letInitToVarCall, Decl(uniqueSymbolsDeclarations.ts, 18, 3)) +>varCall : Symbol(varCall, Decl(uniqueSymbolsDeclarations.ts, 3, 3)) + +let letInitToConstDeclAmbient = constType; +>letInitToConstDeclAmbient : Symbol(letInitToConstDeclAmbient, Decl(uniqueSymbolsDeclarations.ts, 19, 3)) +>constType : Symbol(constType, Decl(uniqueSymbolsDeclarations.ts, 6, 13)) + +var varInitToConstCall = constCall; +>varInitToConstCall : Symbol(varInitToConstCall, Decl(uniqueSymbolsDeclarations.ts, 20, 3)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +var varInitToLetCall = letCall; +>varInitToLetCall : Symbol(varInitToLetCall, Decl(uniqueSymbolsDeclarations.ts, 21, 3)) +>letCall : Symbol(letCall, Decl(uniqueSymbolsDeclarations.ts, 2, 3)) + +var varInitToVarCall = varCall; +>varInitToVarCall : Symbol(varInitToVarCall, Decl(uniqueSymbolsDeclarations.ts, 22, 3)) +>varCall : Symbol(varCall, Decl(uniqueSymbolsDeclarations.ts, 3, 3)) + +var varInitToConstDeclAmbient = constType; +>varInitToConstDeclAmbient : Symbol(varInitToConstDeclAmbient, Decl(uniqueSymbolsDeclarations.ts, 23, 3)) +>constType : Symbol(constType, Decl(uniqueSymbolsDeclarations.ts, 6, 13)) + +// declaration from initializer with type query +const constInitToConstCallWithTypeQuery: typeof constCall = constCall; +>constInitToConstCallWithTypeQuery : Symbol(constInitToConstCallWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 26, 5)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +const constInitToConstDeclAmbientWithTypeQuery: typeof constType = constType; +>constInitToConstDeclAmbientWithTypeQuery : Symbol(constInitToConstDeclAmbientWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 27, 5)) +>constType : Symbol(constType, Decl(uniqueSymbolsDeclarations.ts, 6, 13)) +>constType : Symbol(constType, Decl(uniqueSymbolsDeclarations.ts, 6, 13)) + +// function return inference +function funcReturnConstCall() { return constCall; } +>funcReturnConstCall : Symbol(funcReturnConstCall, Decl(uniqueSymbolsDeclarations.ts, 27, 77)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +function funcReturnLetCall() { return letCall; } +>funcReturnLetCall : Symbol(funcReturnLetCall, Decl(uniqueSymbolsDeclarations.ts, 30, 52)) +>letCall : Symbol(letCall, Decl(uniqueSymbolsDeclarations.ts, 2, 3)) + +function funcReturnVarCall() { return varCall; } +>funcReturnVarCall : Symbol(funcReturnVarCall, Decl(uniqueSymbolsDeclarations.ts, 31, 48)) +>varCall : Symbol(varCall, Decl(uniqueSymbolsDeclarations.ts, 3, 3)) + +// function return value with type query +function funcReturnConstCallWithTypeQuery(): typeof constCall { return constCall; } +>funcReturnConstCallWithTypeQuery : Symbol(funcReturnConstCallWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 32, 48)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +// generator function yield inference +function* genFuncYieldConstCall() { yield constCall; } +>genFuncYieldConstCall : Symbol(genFuncYieldConstCall, Decl(uniqueSymbolsDeclarations.ts, 35, 83)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +function* genFuncYieldLetCall() { yield letCall; } +>genFuncYieldLetCall : Symbol(genFuncYieldLetCall, Decl(uniqueSymbolsDeclarations.ts, 38, 54)) +>letCall : Symbol(letCall, Decl(uniqueSymbolsDeclarations.ts, 2, 3)) + +function* genFuncYieldVarCall() { yield varCall; } +>genFuncYieldVarCall : Symbol(genFuncYieldVarCall, Decl(uniqueSymbolsDeclarations.ts, 39, 50)) +>varCall : Symbol(varCall, Decl(uniqueSymbolsDeclarations.ts, 3, 3)) + +// generator function yield with return type query +function* genFuncYieldConstCallWithTypeQuery(): IterableIterator { yield constCall; } +>genFuncYieldConstCallWithTypeQuery : Symbol(genFuncYieldConstCallWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 40, 50)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.es2015.iterable.d.ts, --, --)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +// async function return inference +async function asyncFuncReturnConstCall() { return constCall; } +>asyncFuncReturnConstCall : Symbol(asyncFuncReturnConstCall, Decl(uniqueSymbolsDeclarations.ts, 43, 103)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +async function asyncFuncReturnLetCall() { return letCall; } +>asyncFuncReturnLetCall : Symbol(asyncFuncReturnLetCall, Decl(uniqueSymbolsDeclarations.ts, 46, 63)) +>letCall : Symbol(letCall, Decl(uniqueSymbolsDeclarations.ts, 2, 3)) + +async function asyncFuncReturnVarCall() { return varCall; } +>asyncFuncReturnVarCall : Symbol(asyncFuncReturnVarCall, Decl(uniqueSymbolsDeclarations.ts, 47, 59)) +>varCall : Symbol(varCall, Decl(uniqueSymbolsDeclarations.ts, 3, 3)) + +// async generator function yield inference +async function* asyncGenFuncYieldConstCall() { yield constCall; } +>asyncGenFuncYieldConstCall : Symbol(asyncGenFuncYieldConstCall, Decl(uniqueSymbolsDeclarations.ts, 48, 59)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +async function* asyncGenFuncYieldLetCall() { yield letCall; } +>asyncGenFuncYieldLetCall : Symbol(asyncGenFuncYieldLetCall, Decl(uniqueSymbolsDeclarations.ts, 51, 65)) +>letCall : Symbol(letCall, Decl(uniqueSymbolsDeclarations.ts, 2, 3)) + +async function* asyncGenFuncYieldVarCall() { yield varCall; } +>asyncGenFuncYieldVarCall : Symbol(asyncGenFuncYieldVarCall, Decl(uniqueSymbolsDeclarations.ts, 52, 61)) +>varCall : Symbol(varCall, Decl(uniqueSymbolsDeclarations.ts, 3, 3)) + +// classes +class C { +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) + + static readonly readonlyStaticCall = Symbol(); +>readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbolsDeclarations.ts, 56, 9)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + + static readonly readonlyStaticType: unique symbol; +>readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbolsDeclarations.ts, 57, 50)) + + static readonly readonlyStaticTypeAndCall: unique symbol = Symbol(); +>readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbolsDeclarations.ts, 58, 54)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + + static readwriteStaticCall = Symbol(); +>readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbolsDeclarations.ts, 59, 72)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + + readonly readonlyCall = Symbol(); +>readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbolsDeclarations.ts, 60, 42)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + + readwriteCall = Symbol(); +>readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbolsDeclarations.ts, 62, 37)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) +} +declare const c: C; +>c : Symbol(c, Decl(uniqueSymbolsDeclarations.ts, 65, 13)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) + +const constInitToCReadonlyStaticCall = C.readonlyStaticCall; +>constInitToCReadonlyStaticCall : Symbol(constInitToCReadonlyStaticCall, Decl(uniqueSymbolsDeclarations.ts, 67, 5)) +>C.readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbolsDeclarations.ts, 56, 9)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbolsDeclarations.ts, 56, 9)) + +const constInitToCReadonlyStaticType = C.readonlyStaticType; +>constInitToCReadonlyStaticType : Symbol(constInitToCReadonlyStaticType, Decl(uniqueSymbolsDeclarations.ts, 68, 5)) +>C.readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbolsDeclarations.ts, 57, 50)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbolsDeclarations.ts, 57, 50)) + +const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; +>constInitToCReadonlyStaticTypeAndCall : Symbol(constInitToCReadonlyStaticTypeAndCall, Decl(uniqueSymbolsDeclarations.ts, 69, 5)) +>C.readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbolsDeclarations.ts, 58, 54)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbolsDeclarations.ts, 58, 54)) + +const constInitToCReadwriteStaticCall = C.readwriteStaticCall; +>constInitToCReadwriteStaticCall : Symbol(constInitToCReadwriteStaticCall, Decl(uniqueSymbolsDeclarations.ts, 70, 5)) +>C.readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbolsDeclarations.ts, 59, 72)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbolsDeclarations.ts, 59, 72)) + +const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall = C.readonlyStaticCall; +>constInitToCReadonlyStaticCallWithTypeQuery : Symbol(constInitToCReadonlyStaticCallWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 72, 5)) +>C.readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbolsDeclarations.ts, 56, 9)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbolsDeclarations.ts, 56, 9)) +>C.readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbolsDeclarations.ts, 56, 9)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbolsDeclarations.ts, 56, 9)) + +const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType = C.readonlyStaticType; +>constInitToCReadonlyStaticTypeWithTypeQuery : Symbol(constInitToCReadonlyStaticTypeWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 73, 5)) +>C.readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbolsDeclarations.ts, 57, 50)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbolsDeclarations.ts, 57, 50)) +>C.readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbolsDeclarations.ts, 57, 50)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbolsDeclarations.ts, 57, 50)) + +const constInitToCReadonlyStaticTypeAndCallWithTypeQuery: typeof C.readonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; +>constInitToCReadonlyStaticTypeAndCallWithTypeQuery : Symbol(constInitToCReadonlyStaticTypeAndCallWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 74, 5)) +>C.readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbolsDeclarations.ts, 58, 54)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbolsDeclarations.ts, 58, 54)) +>C.readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbolsDeclarations.ts, 58, 54)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbolsDeclarations.ts, 58, 54)) + +const constInitToCReadwriteStaticCallWithTypeQuery: typeof C.readwriteStaticCall = C.readwriteStaticCall; +>constInitToCReadwriteStaticCallWithTypeQuery : Symbol(constInitToCReadwriteStaticCallWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 75, 5)) +>C.readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbolsDeclarations.ts, 59, 72)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbolsDeclarations.ts, 59, 72)) +>C.readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbolsDeclarations.ts, 59, 72)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbolsDeclarations.ts, 59, 72)) + +const constInitToCReadonlyCall = c.readonlyCall; +>constInitToCReadonlyCall : Symbol(constInitToCReadonlyCall, Decl(uniqueSymbolsDeclarations.ts, 77, 5)) +>c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbolsDeclarations.ts, 60, 42)) +>c : Symbol(c, Decl(uniqueSymbolsDeclarations.ts, 65, 13)) +>readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbolsDeclarations.ts, 60, 42)) + +const constInitToCReadwriteCall = c.readwriteCall; +>constInitToCReadwriteCall : Symbol(constInitToCReadwriteCall, Decl(uniqueSymbolsDeclarations.ts, 78, 5)) +>c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbolsDeclarations.ts, 62, 37)) +>c : Symbol(c, Decl(uniqueSymbolsDeclarations.ts, 65, 13)) +>readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbolsDeclarations.ts, 62, 37)) + +const constInitToCReadonlyCallWithTypeQuery: typeof c.readonlyCall = c.readonlyCall; +>constInitToCReadonlyCallWithTypeQuery : Symbol(constInitToCReadonlyCallWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 79, 5)) +>c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbolsDeclarations.ts, 60, 42)) +>c : Symbol(c, Decl(uniqueSymbolsDeclarations.ts, 65, 13)) +>readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbolsDeclarations.ts, 60, 42)) +>c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbolsDeclarations.ts, 60, 42)) +>c : Symbol(c, Decl(uniqueSymbolsDeclarations.ts, 65, 13)) +>readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbolsDeclarations.ts, 60, 42)) + +const constInitToCReadwriteCallWithTypeQuery: typeof c.readwriteCall = c.readwriteCall; +>constInitToCReadwriteCallWithTypeQuery : Symbol(constInitToCReadwriteCallWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 80, 5)) +>c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbolsDeclarations.ts, 62, 37)) +>c : Symbol(c, Decl(uniqueSymbolsDeclarations.ts, 65, 13)) +>readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbolsDeclarations.ts, 62, 37)) +>c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbolsDeclarations.ts, 62, 37)) +>c : Symbol(c, Decl(uniqueSymbolsDeclarations.ts, 65, 13)) +>readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbolsDeclarations.ts, 62, 37)) + +const constInitToCReadonlyCallWithIndexedAccess: C["readonlyCall"] = c.readonlyCall; +>constInitToCReadonlyCallWithIndexedAccess : Symbol(constInitToCReadonlyCallWithIndexedAccess, Decl(uniqueSymbolsDeclarations.ts, 81, 5)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbolsDeclarations.ts, 60, 42)) +>c : Symbol(c, Decl(uniqueSymbolsDeclarations.ts, 65, 13)) +>readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbolsDeclarations.ts, 60, 42)) + +const constInitToCReadwriteCallWithIndexedAccess: C["readwriteCall"] = c.readwriteCall; +>constInitToCReadwriteCallWithIndexedAccess : Symbol(constInitToCReadwriteCallWithIndexedAccess, Decl(uniqueSymbolsDeclarations.ts, 82, 5)) +>C : Symbol(C, Decl(uniqueSymbolsDeclarations.ts, 53, 61)) +>c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbolsDeclarations.ts, 62, 37)) +>c : Symbol(c, Decl(uniqueSymbolsDeclarations.ts, 65, 13)) +>readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbolsDeclarations.ts, 62, 37)) + +// interfaces +interface I { +>I : Symbol(I, Decl(uniqueSymbolsDeclarations.ts, 82, 87)) + + readonly readonlyType: unique symbol; +>readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbolsDeclarations.ts, 85, 13)) +} +declare const i: I; +>i : Symbol(i, Decl(uniqueSymbolsDeclarations.ts, 88, 13)) +>I : Symbol(I, Decl(uniqueSymbolsDeclarations.ts, 82, 87)) + +const constInitToIReadonlyType = i.readonlyType; +>constInitToIReadonlyType : Symbol(constInitToIReadonlyType, Decl(uniqueSymbolsDeclarations.ts, 90, 5)) +>i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbolsDeclarations.ts, 85, 13)) +>i : Symbol(i, Decl(uniqueSymbolsDeclarations.ts, 88, 13)) +>readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbolsDeclarations.ts, 85, 13)) + +const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType = i.readonlyType; +>constInitToIReadonlyTypeWithTypeQuery : Symbol(constInitToIReadonlyTypeWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 91, 5)) +>i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbolsDeclarations.ts, 85, 13)) +>i : Symbol(i, Decl(uniqueSymbolsDeclarations.ts, 88, 13)) +>readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbolsDeclarations.ts, 85, 13)) +>i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbolsDeclarations.ts, 85, 13)) +>i : Symbol(i, Decl(uniqueSymbolsDeclarations.ts, 88, 13)) +>readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbolsDeclarations.ts, 85, 13)) + +const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"] = i.readonlyType; +>constInitToIReadonlyTypeWithIndexedAccess : Symbol(constInitToIReadonlyTypeWithIndexedAccess, Decl(uniqueSymbolsDeclarations.ts, 92, 5)) +>I : Symbol(I, Decl(uniqueSymbolsDeclarations.ts, 82, 87)) +>i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbolsDeclarations.ts, 85, 13)) +>i : Symbol(i, Decl(uniqueSymbolsDeclarations.ts, 88, 13)) +>readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbolsDeclarations.ts, 85, 13)) + +// type literals +type L = { +>L : Symbol(L, Decl(uniqueSymbolsDeclarations.ts, 92, 84)) + + readonly readonlyType: unique symbol; +>readonlyType : Symbol(readonlyType, Decl(uniqueSymbolsDeclarations.ts, 95, 10)) + + nested: { +>nested : Symbol(nested, Decl(uniqueSymbolsDeclarations.ts, 96, 41)) + + readonly readonlyNestedType: unique symbol; +>readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbolsDeclarations.ts, 97, 13)) + } +}; +declare const l: L; +>l : Symbol(l, Decl(uniqueSymbolsDeclarations.ts, 101, 13)) +>L : Symbol(L, Decl(uniqueSymbolsDeclarations.ts, 92, 84)) + +const constInitToLReadonlyType = l.readonlyType; +>constInitToLReadonlyType : Symbol(constInitToLReadonlyType, Decl(uniqueSymbolsDeclarations.ts, 103, 5)) +>l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbolsDeclarations.ts, 95, 10)) +>l : Symbol(l, Decl(uniqueSymbolsDeclarations.ts, 101, 13)) +>readonlyType : Symbol(readonlyType, Decl(uniqueSymbolsDeclarations.ts, 95, 10)) + +const constInitToLReadonlyNestedType = l.nested.readonlyNestedType; +>constInitToLReadonlyNestedType : Symbol(constInitToLReadonlyNestedType, Decl(uniqueSymbolsDeclarations.ts, 104, 5)) +>l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbolsDeclarations.ts, 97, 13)) +>l.nested : Symbol(nested, Decl(uniqueSymbolsDeclarations.ts, 96, 41)) +>l : Symbol(l, Decl(uniqueSymbolsDeclarations.ts, 101, 13)) +>nested : Symbol(nested, Decl(uniqueSymbolsDeclarations.ts, 96, 41)) +>readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbolsDeclarations.ts, 97, 13)) + +const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType = l.readonlyType; +>constInitToLReadonlyTypeWithTypeQuery : Symbol(constInitToLReadonlyTypeWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 105, 5)) +>l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbolsDeclarations.ts, 95, 10)) +>l : Symbol(l, Decl(uniqueSymbolsDeclarations.ts, 101, 13)) +>readonlyType : Symbol(readonlyType, Decl(uniqueSymbolsDeclarations.ts, 95, 10)) +>l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbolsDeclarations.ts, 95, 10)) +>l : Symbol(l, Decl(uniqueSymbolsDeclarations.ts, 101, 13)) +>readonlyType : Symbol(readonlyType, Decl(uniqueSymbolsDeclarations.ts, 95, 10)) + +const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType = l.nested.readonlyNestedType; +>constInitToLReadonlyNestedTypeWithTypeQuery : Symbol(constInitToLReadonlyNestedTypeWithTypeQuery, Decl(uniqueSymbolsDeclarations.ts, 106, 5)) +>l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbolsDeclarations.ts, 97, 13)) +>l.nested : Symbol(nested, Decl(uniqueSymbolsDeclarations.ts, 96, 41)) +>l : Symbol(l, Decl(uniqueSymbolsDeclarations.ts, 101, 13)) +>nested : Symbol(nested, Decl(uniqueSymbolsDeclarations.ts, 96, 41)) +>readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbolsDeclarations.ts, 97, 13)) +>l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbolsDeclarations.ts, 97, 13)) +>l.nested : Symbol(nested, Decl(uniqueSymbolsDeclarations.ts, 96, 41)) +>l : Symbol(l, Decl(uniqueSymbolsDeclarations.ts, 101, 13)) +>nested : Symbol(nested, Decl(uniqueSymbolsDeclarations.ts, 96, 41)) +>readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbolsDeclarations.ts, 97, 13)) + +const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"] = l.readonlyType; +>constInitToLReadonlyTypeWithIndexedAccess : Symbol(constInitToLReadonlyTypeWithIndexedAccess, Decl(uniqueSymbolsDeclarations.ts, 107, 5)) +>L : Symbol(L, Decl(uniqueSymbolsDeclarations.ts, 92, 84)) +>l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbolsDeclarations.ts, 95, 10)) +>l : Symbol(l, Decl(uniqueSymbolsDeclarations.ts, 101, 13)) +>readonlyType : Symbol(readonlyType, Decl(uniqueSymbolsDeclarations.ts, 95, 10)) + +const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"] = l.nested.readonlyNestedType; +>constInitToLReadonlyNestedTypeWithIndexedAccess : Symbol(constInitToLReadonlyNestedTypeWithIndexedAccess, Decl(uniqueSymbolsDeclarations.ts, 108, 5)) +>L : Symbol(L, Decl(uniqueSymbolsDeclarations.ts, 92, 84)) +>l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbolsDeclarations.ts, 97, 13)) +>l.nested : Symbol(nested, Decl(uniqueSymbolsDeclarations.ts, 96, 41)) +>l : Symbol(l, Decl(uniqueSymbolsDeclarations.ts, 101, 13)) +>nested : Symbol(nested, Decl(uniqueSymbolsDeclarations.ts, 96, 41)) +>readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbolsDeclarations.ts, 97, 13)) + +// type argument inference +const promiseForConstCall = Promise.resolve(constCall); +>promiseForConstCall : Symbol(promiseForConstCall, Decl(uniqueSymbolsDeclarations.ts, 111, 5)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +const arrayOfConstCall = [constCall]; +>arrayOfConstCall : Symbol(arrayOfConstCall, Decl(uniqueSymbolsDeclarations.ts, 112, 5)) +>constCall : Symbol(constCall, Decl(uniqueSymbolsDeclarations.ts, 1, 5)) + +// unique symbol widening in expressions +declare const s: unique symbol; +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + +declare namespace N { const s: unique symbol; } +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +declare const o: { [s]: "a", [N.s]: "b" }; +>o : Symbol(o, Decl(uniqueSymbolsDeclarations.ts, 117, 13)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +declare function f(x: T): T; +>f : Symbol(f, Decl(uniqueSymbolsDeclarations.ts, 117, 42)) +>T : Symbol(T, Decl(uniqueSymbolsDeclarations.ts, 118, 19)) +>x : Symbol(x, Decl(uniqueSymbolsDeclarations.ts, 118, 22)) +>T : Symbol(T, Decl(uniqueSymbolsDeclarations.ts, 118, 19)) +>T : Symbol(T, Decl(uniqueSymbolsDeclarations.ts, 118, 19)) + +declare function g(x: typeof s): void; +>g : Symbol(g, Decl(uniqueSymbolsDeclarations.ts, 118, 31), Decl(uniqueSymbolsDeclarations.ts, 119, 38)) +>x : Symbol(x, Decl(uniqueSymbolsDeclarations.ts, 119, 19)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + +declare function g(x: typeof N.s): void; +>g : Symbol(g, Decl(uniqueSymbolsDeclarations.ts, 118, 31), Decl(uniqueSymbolsDeclarations.ts, 119, 38)) +>x : Symbol(x, Decl(uniqueSymbolsDeclarations.ts, 120, 19)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +// widening positions + +// argument inference +f(s); +>f : Symbol(f, Decl(uniqueSymbolsDeclarations.ts, 117, 42)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + +f(N.s); +>f : Symbol(f, Decl(uniqueSymbolsDeclarations.ts, 117, 42)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +f(N["s"]); +>f : Symbol(f, Decl(uniqueSymbolsDeclarations.ts, 117, 42)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +// array literal elements +[s]; +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + +[N.s]; +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +[N["s"]]; +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +// property assignments/methods +const o2 = { +>o2 : Symbol(o2, Decl(uniqueSymbolsDeclarations.ts, 135, 5)) + + a: s, +>a : Symbol(a, Decl(uniqueSymbolsDeclarations.ts, 135, 12)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + b: N.s, +>b : Symbol(b, Decl(uniqueSymbolsDeclarations.ts, 136, 9)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + + c: N["s"], +>c : Symbol(c, Decl(uniqueSymbolsDeclarations.ts, 137, 11)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + + method1() { return s; }, +>method1 : Symbol(method1, Decl(uniqueSymbolsDeclarations.ts, 138, 14)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + async method2() { return s; }, +>method2 : Symbol(method2, Decl(uniqueSymbolsDeclarations.ts, 140, 28)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + async * method3() { yield s; }, +>method3 : Symbol(method3, Decl(uniqueSymbolsDeclarations.ts, 141, 34)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + * method4() { yield s; }, +>method4 : Symbol(method4, Decl(uniqueSymbolsDeclarations.ts, 142, 35)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + method5(p = s) { return p; } +>method5 : Symbol(method5, Decl(uniqueSymbolsDeclarations.ts, 143, 29)) +>p : Symbol(p, Decl(uniqueSymbolsDeclarations.ts, 144, 12)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) +>p : Symbol(p, Decl(uniqueSymbolsDeclarations.ts, 144, 12)) + +}; + +// property initializers +class C0 { +>C0 : Symbol(C0, Decl(uniqueSymbolsDeclarations.ts, 145, 2)) + + static readonly a = s; +>a : Symbol(C0.a, Decl(uniqueSymbolsDeclarations.ts, 148, 10)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + static readonly b = N.s; +>b : Symbol(C0.b, Decl(uniqueSymbolsDeclarations.ts, 149, 26)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + + static readonly c = N["s"]; +>c : Symbol(C0.c, Decl(uniqueSymbolsDeclarations.ts, 150, 28)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + + static d = s; +>d : Symbol(C0.d, Decl(uniqueSymbolsDeclarations.ts, 151, 31)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + static e = N.s; +>e : Symbol(C0.e, Decl(uniqueSymbolsDeclarations.ts, 153, 17)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + + static f = N["s"]; +>f : Symbol(C0.f, Decl(uniqueSymbolsDeclarations.ts, 154, 19)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + + readonly a = s; +>a : Symbol(C0.a, Decl(uniqueSymbolsDeclarations.ts, 155, 22)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + readonly b = N.s; +>b : Symbol(C0.b, Decl(uniqueSymbolsDeclarations.ts, 157, 19)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + + readonly c = N["s"]; +>c : Symbol(C0.c, Decl(uniqueSymbolsDeclarations.ts, 158, 21)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + + d = s; +>d : Symbol(C0.d, Decl(uniqueSymbolsDeclarations.ts, 159, 24)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + e = N.s; +>e : Symbol(C0.e, Decl(uniqueSymbolsDeclarations.ts, 161, 10)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + + f = N["s"]; +>f : Symbol(C0.f, Decl(uniqueSymbolsDeclarations.ts, 162, 12)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + + method1() { return s; } +>method1 : Symbol(C0.method1, Decl(uniqueSymbolsDeclarations.ts, 163, 15)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + async method2() { return s; } +>method2 : Symbol(C0.method2, Decl(uniqueSymbolsDeclarations.ts, 165, 27)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + async * method3() { yield s; } +>method3 : Symbol(C0.method3, Decl(uniqueSymbolsDeclarations.ts, 166, 33)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + * method4() { yield s; } +>method4 : Symbol(C0.method4, Decl(uniqueSymbolsDeclarations.ts, 167, 34)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + method5(p = s) { return p; } +>method5 : Symbol(C0.method5, Decl(uniqueSymbolsDeclarations.ts, 168, 28)) +>p : Symbol(p, Decl(uniqueSymbolsDeclarations.ts, 169, 12)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) +>p : Symbol(p, Decl(uniqueSymbolsDeclarations.ts, 169, 12)) +} + +// non-widening positions + +// element access +o[s]; +>o : Symbol(o, Decl(uniqueSymbolsDeclarations.ts, 117, 13)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + +o[N.s]; +>o : Symbol(o, Decl(uniqueSymbolsDeclarations.ts, 117, 13)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +o[N["s"]]; +>o : Symbol(o, Decl(uniqueSymbolsDeclarations.ts, 117, 13)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +// arguments (no-inference) +f(s); +>f : Symbol(f, Decl(uniqueSymbolsDeclarations.ts, 117, 42)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + +f(N.s); +>f : Symbol(f, Decl(uniqueSymbolsDeclarations.ts, 117, 42)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +f(N["s"]); +>f : Symbol(f, Decl(uniqueSymbolsDeclarations.ts, 117, 42)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +g(s); +>g : Symbol(g, Decl(uniqueSymbolsDeclarations.ts, 118, 31), Decl(uniqueSymbolsDeclarations.ts, 119, 38)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + +g(N.s); +>g : Symbol(g, Decl(uniqueSymbolsDeclarations.ts, 118, 31), Decl(uniqueSymbolsDeclarations.ts, 119, 38)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +g(N["s"]); +>g : Symbol(g, Decl(uniqueSymbolsDeclarations.ts, 118, 31), Decl(uniqueSymbolsDeclarations.ts, 119, 38)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +// falsy expressions +s || ""; +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + +N.s || ""; +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +N["s"] || ""; +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +// conditionals +Math.random() * 2 ? s : "a"; +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + +Math.random() * 2 ? N.s : "a"; +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +Math.random() * 2 ? N["s"] : "a"; +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +// computed property names +({ + [s]: "a", +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + [N.s]: "b", +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + +}); + +class C1 { +>C1 : Symbol(C1, Decl(uniqueSymbolsDeclarations.ts, 201, 3)) + + static [s]: "a"; +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + static [N.s]: "b"; +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) + + [s]: "a"; +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + [N.s]: "b"; +>N.s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbolsDeclarations.ts, 115, 31)) +>s : Symbol(N.s, Decl(uniqueSymbolsDeclarations.ts, 116, 27)) +} + +// contextual types + +interface Context { +>Context : Symbol(Context, Decl(uniqueSymbolsDeclarations.ts, 209, 1)) + + method1(): typeof s; +>method1 : Symbol(Context.method1, Decl(uniqueSymbolsDeclarations.ts, 213, 19)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + method2(): Promise; +>method2 : Symbol(Context.method2, Decl(uniqueSymbolsDeclarations.ts, 214, 24)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + method3(): AsyncIterableIterator; +>method3 : Symbol(Context.method3, Decl(uniqueSymbolsDeclarations.ts, 215, 33)) +>AsyncIterableIterator : Symbol(AsyncIterableIterator, Decl(lib.esnext.asynciterable.d.ts, --, --)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + method4(): IterableIterator; +>method4 : Symbol(Context.method4, Decl(uniqueSymbolsDeclarations.ts, 216, 47)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.es2015.iterable.d.ts, --, --)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + method5(p?: typeof s): typeof s; +>method5 : Symbol(Context.method5, Decl(uniqueSymbolsDeclarations.ts, 217, 42)) +>p : Symbol(p, Decl(uniqueSymbolsDeclarations.ts, 218, 12)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) +} + +const o4: Context = { +>o4 : Symbol(o4, Decl(uniqueSymbolsDeclarations.ts, 221, 5)) +>Context : Symbol(Context, Decl(uniqueSymbolsDeclarations.ts, 209, 1)) + + method1() { +>method1 : Symbol(method1, Decl(uniqueSymbolsDeclarations.ts, 221, 21)) + + return s; // return type should not widen due to contextual type +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + }, + async method2() { +>method2 : Symbol(method2, Decl(uniqueSymbolsDeclarations.ts, 224, 6)) + + return s; // return type should not widen due to contextual type +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + }, + async * method3() { +>method3 : Symbol(method3, Decl(uniqueSymbolsDeclarations.ts, 227, 6)) + + yield s; // yield type should not widen due to contextual type +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + }, + * method4() { +>method4 : Symbol(method4, Decl(uniqueSymbolsDeclarations.ts, 230, 6)) + + yield s; // yield type should not widen due to contextual type +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + }, + method5(p = s) { // parameter should not widen due to contextual type +>method5 : Symbol(method5, Decl(uniqueSymbolsDeclarations.ts, 233, 6)) +>p : Symbol(p, Decl(uniqueSymbolsDeclarations.ts, 234, 12)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarations.ts, 115, 13)) + + return p; +>p : Symbol(p, Decl(uniqueSymbolsDeclarations.ts, 234, 12)) + } +}; diff --git a/tests/baselines/reference/uniqueSymbolsDeclarations.types b/tests/baselines/reference/uniqueSymbolsDeclarations.types new file mode 100644 index 00000000000..c4975d497cc --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarations.types @@ -0,0 +1,867 @@ +=== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarations.ts === +// declarations with call initializer +const constCall = Symbol(); +>constCall : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +let letCall = Symbol(); +>letCall : symbol +>Symbol() : symbol +>Symbol : SymbolConstructor + +var varCall = Symbol(); +>varCall : symbol +>Symbol() : symbol +>Symbol : SymbolConstructor + +// ambient declaration with type +declare const constType: unique symbol; +>constType : unique symbol + +// declaration with type and call initializer +const constTypeAndCall: unique symbol = Symbol(); +>constTypeAndCall : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +// declaration from initializer +const constInitToConstCall = constCall; +>constInitToConstCall : symbol +>constCall : unique symbol + +const constInitToLetCall = letCall; +>constInitToLetCall : symbol +>letCall : symbol + +const constInitToVarCall = varCall; +>constInitToVarCall : symbol +>varCall : symbol + +const constInitToConstDeclAmbient = constType; +>constInitToConstDeclAmbient : symbol +>constType : unique symbol + +let letInitToConstCall = constCall; +>letInitToConstCall : symbol +>constCall : unique symbol + +let letInitToLetCall = letCall; +>letInitToLetCall : symbol +>letCall : symbol + +let letInitToVarCall = varCall; +>letInitToVarCall : symbol +>varCall : symbol + +let letInitToConstDeclAmbient = constType; +>letInitToConstDeclAmbient : symbol +>constType : unique symbol + +var varInitToConstCall = constCall; +>varInitToConstCall : symbol +>constCall : unique symbol + +var varInitToLetCall = letCall; +>varInitToLetCall : symbol +>letCall : symbol + +var varInitToVarCall = varCall; +>varInitToVarCall : symbol +>varCall : symbol + +var varInitToConstDeclAmbient = constType; +>varInitToConstDeclAmbient : symbol +>constType : unique symbol + +// declaration from initializer with type query +const constInitToConstCallWithTypeQuery: typeof constCall = constCall; +>constInitToConstCallWithTypeQuery : unique symbol +>constCall : unique symbol +>constCall : unique symbol + +const constInitToConstDeclAmbientWithTypeQuery: typeof constType = constType; +>constInitToConstDeclAmbientWithTypeQuery : unique symbol +>constType : unique symbol +>constType : unique symbol + +// function return inference +function funcReturnConstCall() { return constCall; } +>funcReturnConstCall : () => symbol +>constCall : unique symbol + +function funcReturnLetCall() { return letCall; } +>funcReturnLetCall : () => symbol +>letCall : symbol + +function funcReturnVarCall() { return varCall; } +>funcReturnVarCall : () => symbol +>varCall : symbol + +// function return value with type query +function funcReturnConstCallWithTypeQuery(): typeof constCall { return constCall; } +>funcReturnConstCallWithTypeQuery : () => unique symbol +>constCall : unique symbol +>constCall : unique symbol + +// generator function yield inference +function* genFuncYieldConstCall() { yield constCall; } +>genFuncYieldConstCall : () => IterableIterator +>yield constCall : any +>constCall : unique symbol + +function* genFuncYieldLetCall() { yield letCall; } +>genFuncYieldLetCall : () => IterableIterator +>yield letCall : any +>letCall : symbol + +function* genFuncYieldVarCall() { yield varCall; } +>genFuncYieldVarCall : () => IterableIterator +>yield varCall : any +>varCall : symbol + +// generator function yield with return type query +function* genFuncYieldConstCallWithTypeQuery(): IterableIterator { yield constCall; } +>genFuncYieldConstCallWithTypeQuery : () => IterableIterator +>IterableIterator : IterableIterator +>constCall : unique symbol +>yield constCall : any +>constCall : unique symbol + +// async function return inference +async function asyncFuncReturnConstCall() { return constCall; } +>asyncFuncReturnConstCall : () => Promise +>constCall : unique symbol + +async function asyncFuncReturnLetCall() { return letCall; } +>asyncFuncReturnLetCall : () => Promise +>letCall : symbol + +async function asyncFuncReturnVarCall() { return varCall; } +>asyncFuncReturnVarCall : () => Promise +>varCall : symbol + +// async generator function yield inference +async function* asyncGenFuncYieldConstCall() { yield constCall; } +>asyncGenFuncYieldConstCall : () => AsyncIterableIterator +>yield constCall : any +>constCall : unique symbol + +async function* asyncGenFuncYieldLetCall() { yield letCall; } +>asyncGenFuncYieldLetCall : () => AsyncIterableIterator +>yield letCall : any +>letCall : symbol + +async function* asyncGenFuncYieldVarCall() { yield varCall; } +>asyncGenFuncYieldVarCall : () => AsyncIterableIterator +>yield varCall : any +>varCall : symbol + +// classes +class C { +>C : C + + static readonly readonlyStaticCall = Symbol(); +>readonlyStaticCall : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + + static readonly readonlyStaticType: unique symbol; +>readonlyStaticType : unique symbol + + static readonly readonlyStaticTypeAndCall: unique symbol = Symbol(); +>readonlyStaticTypeAndCall : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + + static readwriteStaticCall = Symbol(); +>readwriteStaticCall : symbol +>Symbol() : symbol +>Symbol : SymbolConstructor + + readonly readonlyCall = Symbol(); +>readonlyCall : symbol +>Symbol() : symbol +>Symbol : SymbolConstructor + + readwriteCall = Symbol(); +>readwriteCall : symbol +>Symbol() : symbol +>Symbol : SymbolConstructor +} +declare const c: C; +>c : C +>C : C + +const constInitToCReadonlyStaticCall = C.readonlyStaticCall; +>constInitToCReadonlyStaticCall : symbol +>C.readonlyStaticCall : unique symbol +>C : typeof C +>readonlyStaticCall : unique symbol + +const constInitToCReadonlyStaticType = C.readonlyStaticType; +>constInitToCReadonlyStaticType : symbol +>C.readonlyStaticType : unique symbol +>C : typeof C +>readonlyStaticType : unique symbol + +const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; +>constInitToCReadonlyStaticTypeAndCall : symbol +>C.readonlyStaticTypeAndCall : unique symbol +>C : typeof C +>readonlyStaticTypeAndCall : unique symbol + +const constInitToCReadwriteStaticCall = C.readwriteStaticCall; +>constInitToCReadwriteStaticCall : symbol +>C.readwriteStaticCall : symbol +>C : typeof C +>readwriteStaticCall : symbol + +const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall = C.readonlyStaticCall; +>constInitToCReadonlyStaticCallWithTypeQuery : unique symbol +>C.readonlyStaticCall : unique symbol +>C : typeof C +>readonlyStaticCall : unique symbol +>C.readonlyStaticCall : unique symbol +>C : typeof C +>readonlyStaticCall : unique symbol + +const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType = C.readonlyStaticType; +>constInitToCReadonlyStaticTypeWithTypeQuery : unique symbol +>C.readonlyStaticType : unique symbol +>C : typeof C +>readonlyStaticType : unique symbol +>C.readonlyStaticType : unique symbol +>C : typeof C +>readonlyStaticType : unique symbol + +const constInitToCReadonlyStaticTypeAndCallWithTypeQuery: typeof C.readonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; +>constInitToCReadonlyStaticTypeAndCallWithTypeQuery : unique symbol +>C.readonlyStaticTypeAndCall : unique symbol +>C : typeof C +>readonlyStaticTypeAndCall : unique symbol +>C.readonlyStaticTypeAndCall : unique symbol +>C : typeof C +>readonlyStaticTypeAndCall : unique symbol + +const constInitToCReadwriteStaticCallWithTypeQuery: typeof C.readwriteStaticCall = C.readwriteStaticCall; +>constInitToCReadwriteStaticCallWithTypeQuery : symbol +>C.readwriteStaticCall : symbol +>C : typeof C +>readwriteStaticCall : symbol +>C.readwriteStaticCall : symbol +>C : typeof C +>readwriteStaticCall : symbol + +const constInitToCReadonlyCall = c.readonlyCall; +>constInitToCReadonlyCall : symbol +>c.readonlyCall : symbol +>c : C +>readonlyCall : symbol + +const constInitToCReadwriteCall = c.readwriteCall; +>constInitToCReadwriteCall : symbol +>c.readwriteCall : symbol +>c : C +>readwriteCall : symbol + +const constInitToCReadonlyCallWithTypeQuery: typeof c.readonlyCall = c.readonlyCall; +>constInitToCReadonlyCallWithTypeQuery : symbol +>c.readonlyCall : symbol +>c : C +>readonlyCall : symbol +>c.readonlyCall : symbol +>c : C +>readonlyCall : symbol + +const constInitToCReadwriteCallWithTypeQuery: typeof c.readwriteCall = c.readwriteCall; +>constInitToCReadwriteCallWithTypeQuery : symbol +>c.readwriteCall : symbol +>c : C +>readwriteCall : symbol +>c.readwriteCall : symbol +>c : C +>readwriteCall : symbol + +const constInitToCReadonlyCallWithIndexedAccess: C["readonlyCall"] = c.readonlyCall; +>constInitToCReadonlyCallWithIndexedAccess : symbol +>C : C +>c.readonlyCall : symbol +>c : C +>readonlyCall : symbol + +const constInitToCReadwriteCallWithIndexedAccess: C["readwriteCall"] = c.readwriteCall; +>constInitToCReadwriteCallWithIndexedAccess : symbol +>C : C +>c.readwriteCall : symbol +>c : C +>readwriteCall : symbol + +// interfaces +interface I { +>I : I + + readonly readonlyType: unique symbol; +>readonlyType : unique symbol +} +declare const i: I; +>i : I +>I : I + +const constInitToIReadonlyType = i.readonlyType; +>constInitToIReadonlyType : symbol +>i.readonlyType : unique symbol +>i : I +>readonlyType : unique symbol + +const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType = i.readonlyType; +>constInitToIReadonlyTypeWithTypeQuery : unique symbol +>i.readonlyType : unique symbol +>i : I +>readonlyType : unique symbol +>i.readonlyType : unique symbol +>i : I +>readonlyType : unique symbol + +const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"] = i.readonlyType; +>constInitToIReadonlyTypeWithIndexedAccess : unique symbol +>I : I +>i.readonlyType : unique symbol +>i : I +>readonlyType : unique symbol + +// type literals +type L = { +>L : L + + readonly readonlyType: unique symbol; +>readonlyType : unique symbol + + nested: { +>nested : { readonly readonlyNestedType: unique symbol; } + + readonly readonlyNestedType: unique symbol; +>readonlyNestedType : unique symbol + } +}; +declare const l: L; +>l : L +>L : L + +const constInitToLReadonlyType = l.readonlyType; +>constInitToLReadonlyType : symbol +>l.readonlyType : unique symbol +>l : L +>readonlyType : unique symbol + +const constInitToLReadonlyNestedType = l.nested.readonlyNestedType; +>constInitToLReadonlyNestedType : symbol +>l.nested.readonlyNestedType : unique symbol +>l.nested : { readonly readonlyNestedType: unique symbol; } +>l : L +>nested : { readonly readonlyNestedType: unique symbol; } +>readonlyNestedType : unique symbol + +const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType = l.readonlyType; +>constInitToLReadonlyTypeWithTypeQuery : unique symbol +>l.readonlyType : unique symbol +>l : L +>readonlyType : unique symbol +>l.readonlyType : unique symbol +>l : L +>readonlyType : unique symbol + +const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType = l.nested.readonlyNestedType; +>constInitToLReadonlyNestedTypeWithTypeQuery : unique symbol +>l.nested.readonlyNestedType : unique symbol +>l.nested : { readonly readonlyNestedType: unique symbol; } +>l : L +>nested : { readonly readonlyNestedType: unique symbol; } +>readonlyNestedType : unique symbol +>l.nested.readonlyNestedType : unique symbol +>l.nested : { readonly readonlyNestedType: unique symbol; } +>l : L +>nested : { readonly readonlyNestedType: unique symbol; } +>readonlyNestedType : unique symbol + +const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"] = l.readonlyType; +>constInitToLReadonlyTypeWithIndexedAccess : unique symbol +>L : L +>l.readonlyType : unique symbol +>l : L +>readonlyType : unique symbol + +const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"] = l.nested.readonlyNestedType; +>constInitToLReadonlyNestedTypeWithIndexedAccess : unique symbol +>L : L +>l.nested.readonlyNestedType : unique symbol +>l.nested : { readonly readonlyNestedType: unique symbol; } +>l : L +>nested : { readonly readonlyNestedType: unique symbol; } +>readonlyNestedType : unique symbol + +// type argument inference +const promiseForConstCall = Promise.resolve(constCall); +>promiseForConstCall : Promise +>Promise.resolve(constCall) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>constCall : unique symbol + +const arrayOfConstCall = [constCall]; +>arrayOfConstCall : symbol[] +>[constCall] : symbol[] +>constCall : unique symbol + +// unique symbol widening in expressions +declare const s: unique symbol; +>s : unique symbol + +declare namespace N { const s: unique symbol; } +>N : typeof N +>s : unique symbol + +declare const o: { [s]: "a", [N.s]: "b" }; +>o : { [s]: "a"; [N.s]: "b"; } +>s : unique symbol +>N.s : unique symbol +>N : typeof N +>s : unique symbol + +declare function f(x: T): T; +>f : (x: T) => T +>T : T +>x : T +>T : T +>T : T + +declare function g(x: typeof s): void; +>g : { (x: unique symbol): void; (x: unique symbol): void; } +>x : unique symbol +>s : unique symbol + +declare function g(x: typeof N.s): void; +>g : { (x: unique symbol): void; (x: unique symbol): void; } +>x : unique symbol +>N.s : unique symbol +>N : typeof N +>s : unique symbol + +// widening positions + +// argument inference +f(s); +>f(s) : symbol +>f : (x: T) => T +>s : unique symbol + +f(N.s); +>f(N.s) : symbol +>f : (x: T) => T +>N.s : unique symbol +>N : typeof N +>s : unique symbol + +f(N["s"]); +>f(N["s"]) : symbol +>f : (x: T) => T +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" + +// array literal elements +[s]; +>[s] : symbol[] +>s : unique symbol + +[N.s]; +>[N.s] : symbol[] +>N.s : unique symbol +>N : typeof N +>s : unique symbol + +[N["s"]]; +>[N["s"]] : symbol[] +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" + +// property assignments/methods +const o2 = { +>o2 : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncIterableIterator; method4(): IterableIterator; method5(p?: symbol): symbol; } +>{ a: s, b: N.s, c: N["s"], method1() { return s; }, async method2() { return s; }, async * method3() { yield s; }, * method4() { yield s; }, method5(p = s) { return p; }} : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncIterableIterator; method4(): IterableIterator; method5(p?: symbol): symbol; } + + a: s, +>a : symbol +>s : unique symbol + + b: N.s, +>b : symbol +>N.s : unique symbol +>N : typeof N +>s : unique symbol + + c: N["s"], +>c : symbol +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" + + method1() { return s; }, +>method1 : () => symbol +>s : unique symbol + + async method2() { return s; }, +>method2 : () => Promise +>s : unique symbol + + async * method3() { yield s; }, +>method3 : () => AsyncIterableIterator +>yield s : any +>s : unique symbol + + * method4() { yield s; }, +>method4 : () => IterableIterator +>yield s : any +>s : unique symbol + + method5(p = s) { return p; } +>method5 : (p?: symbol) => symbol +>p : symbol +>s : unique symbol +>p : symbol + +}; + +// property initializers +class C0 { +>C0 : C0 + + static readonly a = s; +>a : symbol +>s : unique symbol + + static readonly b = N.s; +>b : symbol +>N.s : unique symbol +>N : typeof N +>s : unique symbol + + static readonly c = N["s"]; +>c : symbol +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" + + static d = s; +>d : symbol +>s : unique symbol + + static e = N.s; +>e : symbol +>N.s : unique symbol +>N : typeof N +>s : unique symbol + + static f = N["s"]; +>f : symbol +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" + + readonly a = s; +>a : symbol +>s : unique symbol + + readonly b = N.s; +>b : symbol +>N.s : unique symbol +>N : typeof N +>s : unique symbol + + readonly c = N["s"]; +>c : symbol +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" + + d = s; +>d : symbol +>s : unique symbol + + e = N.s; +>e : symbol +>N.s : unique symbol +>N : typeof N +>s : unique symbol + + f = N["s"]; +>f : symbol +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" + + method1() { return s; } +>method1 : () => symbol +>s : unique symbol + + async method2() { return s; } +>method2 : () => Promise +>s : unique symbol + + async * method3() { yield s; } +>method3 : () => AsyncIterableIterator +>yield s : any +>s : unique symbol + + * method4() { yield s; } +>method4 : () => IterableIterator +>yield s : any +>s : unique symbol + + method5(p = s) { return p; } +>method5 : (p?: symbol) => symbol +>p : symbol +>s : unique symbol +>p : symbol +} + +// non-widening positions + +// element access +o[s]; +>o[s] : "a" +>o : { [s]: "a"; [N.s]: "b"; } +>s : unique symbol + +o[N.s]; +>o[N.s] : "b" +>o : { [s]: "a"; [N.s]: "b"; } +>N.s : unique symbol +>N : typeof N +>s : unique symbol + +o[N["s"]]; +>o[N["s"]] : "b" +>o : { [s]: "a"; [N.s]: "b"; } +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" + +// arguments (no-inference) +f(s); +>f(s) : unique symbol +>f : (x: T) => T +>s : unique symbol +>s : unique symbol + +f(N.s); +>f(N.s) : unique symbol +>f : (x: T) => T +>N.s : unique symbol +>N : typeof N +>s : unique symbol +>N.s : unique symbol +>N : typeof N +>s : unique symbol + +f(N["s"]); +>f(N["s"]) : unique symbol +>f : (x: T) => T +>N.s : unique symbol +>N : typeof N +>s : unique symbol +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" + +g(s); +>g(s) : void +>g : { (x: unique symbol): void; (x: unique symbol): void; } +>s : unique symbol + +g(N.s); +>g(N.s) : void +>g : { (x: unique symbol): void; (x: unique symbol): void; } +>N.s : unique symbol +>N : typeof N +>s : unique symbol + +g(N["s"]); +>g(N["s"]) : void +>g : { (x: unique symbol): void; (x: unique symbol): void; } +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" + +// falsy expressions +s || ""; +>s || "" : unique symbol | "" +>s : unique symbol +>"" : "" + +N.s || ""; +>N.s || "" : unique symbol | "" +>N.s : unique symbol +>N : typeof N +>s : unique symbol +>"" : "" + +N["s"] || ""; +>N["s"] || "" : unique symbol | "" +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" +>"" : "" + +// conditionals +Math.random() * 2 ? s : "a"; +>Math.random() * 2 ? s : "a" : unique symbol | "a" +>Math.random() * 2 : number +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>2 : 2 +>s : unique symbol +>"a" : "a" + +Math.random() * 2 ? N.s : "a"; +>Math.random() * 2 ? N.s : "a" : unique symbol | "a" +>Math.random() * 2 : number +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>2 : 2 +>N.s : unique symbol +>N : typeof N +>s : unique symbol +>"a" : "a" + +Math.random() * 2 ? N["s"] : "a"; +>Math.random() * 2 ? N["s"] : "a" : unique symbol | "a" +>Math.random() * 2 : number +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>2 : 2 +>N["s"] : unique symbol +>N : typeof N +>"s" : "s" +>"a" : "a" + +// computed property names +({ +>({ [s]: "a", [N.s]: "b",}) : { [s]: string; [N.s]: string; } +>{ [s]: "a", [N.s]: "b",} : { [s]: string; [N.s]: string; } + + [s]: "a", +>s : unique symbol +>"a" : "a" + + [N.s]: "b", +>N.s : unique symbol +>N : typeof N +>s : unique symbol +>"b" : "b" + +}); + +class C1 { +>C1 : C1 + + static [s]: "a"; +>s : unique symbol + + static [N.s]: "b"; +>N.s : unique symbol +>N : typeof N +>s : unique symbol + + [s]: "a"; +>s : unique symbol + + [N.s]: "b"; +>N.s : unique symbol +>N : typeof N +>s : unique symbol +} + +// contextual types + +interface Context { +>Context : Context + + method1(): typeof s; +>method1 : () => unique symbol +>s : unique symbol + + method2(): Promise; +>method2 : () => Promise +>Promise : Promise +>s : unique symbol + + method3(): AsyncIterableIterator; +>method3 : () => AsyncIterableIterator +>AsyncIterableIterator : AsyncIterableIterator +>s : unique symbol + + method4(): IterableIterator; +>method4 : () => IterableIterator +>IterableIterator : IterableIterator +>s : unique symbol + + method5(p?: typeof s): typeof s; +>method5 : (p?: unique symbol) => unique symbol +>p : unique symbol +>s : unique symbol +>s : unique symbol +} + +const o4: Context = { +>o4 : Context +>Context : Context +>{ method1() { return s; // return type should not widen due to contextual type }, async method2() { return s; // return type should not widen due to contextual type }, async * method3() { yield s; // yield type should not widen due to contextual type }, * method4() { yield s; // yield type should not widen due to contextual type }, method5(p = s) { // parameter should not widen due to contextual type return p; }} : { method1(): unique symbol; method2(): Promise; method3(): AsyncIterableIterator; method4(): IterableIterator; method5(p?: unique symbol): unique symbol; } + + method1() { +>method1 : () => unique symbol + + return s; // return type should not widen due to contextual type +>s : unique symbol + + }, + async method2() { +>method2 : () => Promise + + return s; // return type should not widen due to contextual type +>s : unique symbol + + }, + async * method3() { +>method3 : () => AsyncIterableIterator + + yield s; // yield type should not widen due to contextual type +>yield s : any +>s : unique symbol + + }, + * method4() { +>method4 : () => IterableIterator + + yield s; // yield type should not widen due to contextual type +>yield s : any +>s : unique symbol + + }, + method5(p = s) { // parameter should not widen due to contextual type +>method5 : (p?: unique symbol) => unique symbol +>p : unique symbol +>s : unique symbol + + return p; +>p : unique symbol + } +}; diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.errors.txt b/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.errors.txt new file mode 100644 index 00000000000..f7769db1077 --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.errors.txt @@ -0,0 +1,110 @@ +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(6,14): error TS2527: The inferred type of 'obj' references an inaccessible 'unique symbol' type. A type annotation is necessary. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(15,14): error TS2527: The inferred type of 'classExpression' references an inaccessible 'unique symbol' type. A type annotation is necessary. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(24,17): error TS2527: The inferred type of 'funcInferredReturnType' references an inaccessible 'unique symbol' type. A type annotation is necessary. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(24,64): error TS4078: Parameter 'obj' of exported function has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(29,6): error TS4033: Property '[s]' of exported interface has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(33,6): error TS4102: Method '[s]' of exported interface has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(37,6): error TS4033: Property '[s]' of exported interface has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(41,6): error TS4102: Method '[s]' of exported interface has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(45,6): error TS4031: Public property '[s]' of exported class has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(46,13): error TS4028: Public static property '[s]' of exported class has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(50,6): error TS4100: Public method '[s]' of exported class has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(51,13): error TS4097: Public static method '[s]' of exported class has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(55,10): error TS4031: Public property '[s]' of exported class has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(56,10): error TS4031: Public property '[s]' of exported class has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(57,17): error TS4028: Public static property '[s]' of exported class has or is using private name 's'. +tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts(58,17): error TS4028: Public static property '[s]' of exported class has or is using private name 's'. + + +==== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts (16 errors) ==== + declare const s: unique symbol; + interface I { readonly readonlyType: unique symbol; } + + // not allowed when emitting declarations + + export const obj = { + ~~~ +!!! error TS2527: The inferred type of 'obj' references an inaccessible 'unique symbol' type. A type annotation is necessary. + method1(p: typeof s): typeof s { + return p; + }, + method2(p: I["readonlyType"]): I["readonlyType"] { + return p; + } + }; + + export const classExpression = class { + ~~~~~~~~~~~~~~~ +!!! error TS2527: The inferred type of 'classExpression' references an inaccessible 'unique symbol' type. A type annotation is necessary. + method1(p: typeof s): typeof s { + return p; + } + method2(p: I["readonlyType"]): I["readonlyType"] { + return p; + } + }; + + export function funcInferredReturnType(obj: { method(p: typeof s): void }) { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2527: The inferred type of 'funcInferredReturnType' references an inaccessible 'unique symbol' type. A type annotation is necessary. + ~ +!!! error TS4078: Parameter 'obj' of exported function has or is using private name 's'. + return obj; + } + + export interface InterfaceWithPrivateNamedProperties { + [s]: any; + ~ +!!! error TS4033: Property '[s]' of exported interface has or is using private name 's'. + } + + export interface InterfaceWithPrivateNamedMethods { + [s](): any; + ~ +!!! error TS4102: Method '[s]' of exported interface has or is using private name 's'. + } + + export type TypeLiteralWithPrivateNamedProperties = { + [s]: any; + ~ +!!! error TS4033: Property '[s]' of exported interface has or is using private name 's'. + } + + export type TypeLiteralWithPrivateNamedMethods = { + [s](): any; + ~ +!!! error TS4102: Method '[s]' of exported interface has or is using private name 's'. + } + + export class ClassWithPrivateNamedProperties { + [s]: any; + ~ +!!! error TS4031: Public property '[s]' of exported class has or is using private name 's'. + static [s]: any; + ~ +!!! error TS4028: Public static property '[s]' of exported class has or is using private name 's'. + } + + export class ClassWithPrivateNamedMethods { + [s]() {} + ~ +!!! error TS4100: Public method '[s]' of exported class has or is using private name 's'. + static [s]() {} + ~ +!!! error TS4097: Public static method '[s]' of exported class has or is using private name 's'. + } + + export class ClassWithPrivateNamedAccessors { + get [s](): any { return undefined; } + ~ +!!! error TS4031: Public property '[s]' of exported class has or is using private name 's'. + set [s](v: any) { } + ~ +!!! error TS4031: Public property '[s]' of exported class has or is using private name 's'. + static get [s](): any { return undefined; } + ~ +!!! error TS4028: Public static property '[s]' of exported class has or is using private name 's'. + static set [s](v: any) { } + ~ +!!! error TS4028: Public static property '[s]' of exported class has or is using private name 's'. + } \ No newline at end of file diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.js b/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.js new file mode 100644 index 00000000000..a446a6712a4 --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.js @@ -0,0 +1,100 @@ +//// [uniqueSymbolsDeclarationsErrors.ts] +declare const s: unique symbol; +interface I { readonly readonlyType: unique symbol; } + +// not allowed when emitting declarations + +export const obj = { + method1(p: typeof s): typeof s { + return p; + }, + method2(p: I["readonlyType"]): I["readonlyType"] { + return p; + } +}; + +export const classExpression = class { + method1(p: typeof s): typeof s { + return p; + } + method2(p: I["readonlyType"]): I["readonlyType"] { + return p; + } +}; + +export function funcInferredReturnType(obj: { method(p: typeof s): void }) { + return obj; +} + +export interface InterfaceWithPrivateNamedProperties { + [s]: any; +} + +export interface InterfaceWithPrivateNamedMethods { + [s](): any; +} + +export type TypeLiteralWithPrivateNamedProperties = { + [s]: any; +} + +export type TypeLiteralWithPrivateNamedMethods = { + [s](): any; +} + +export class ClassWithPrivateNamedProperties { + [s]: any; + static [s]: any; +} + +export class ClassWithPrivateNamedMethods { + [s]() {} + static [s]() {} +} + +export class ClassWithPrivateNamedAccessors { + get [s](): any { return undefined; } + set [s](v: any) { } + static get [s](): any { return undefined; } + static set [s](v: any) { } +} + +//// [uniqueSymbolsDeclarationsErrors.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +// not allowed when emitting declarations +exports.obj = { + method1(p) { + return p; + }, + method2(p) { + return p; + } +}; +exports.classExpression = class { + method1(p) { + return p; + } + method2(p) { + return p; + } +}; +function funcInferredReturnType(obj) { + return obj; +} +exports.funcInferredReturnType = funcInferredReturnType; +class ClassWithPrivateNamedProperties { +} +exports.ClassWithPrivateNamedProperties = ClassWithPrivateNamedProperties; +class ClassWithPrivateNamedMethods { + [s]() { } + static [s]() { } +} +exports.ClassWithPrivateNamedMethods = ClassWithPrivateNamedMethods; +class ClassWithPrivateNamedAccessors { + get [s]() { return undefined; } + set [s](v) { } + static get [s]() { return undefined; } + static set [s](v) { } +} +exports.ClassWithPrivateNamedAccessors = ClassWithPrivateNamedAccessors; diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.symbols b/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.symbols new file mode 100644 index 00000000000..45275c60a17 --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.symbols @@ -0,0 +1,135 @@ +=== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts === +declare const s: unique symbol; +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) + +interface I { readonly readonlyType: unique symbol; } +>I : Symbol(I, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 31)) +>readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbolsDeclarationsErrors.ts, 1, 13)) + +// not allowed when emitting declarations + +export const obj = { +>obj : Symbol(obj, Decl(uniqueSymbolsDeclarationsErrors.ts, 5, 12)) + + method1(p: typeof s): typeof s { +>method1 : Symbol(method1, Decl(uniqueSymbolsDeclarationsErrors.ts, 5, 20)) +>p : Symbol(p, Decl(uniqueSymbolsDeclarationsErrors.ts, 6, 12)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) + + return p; +>p : Symbol(p, Decl(uniqueSymbolsDeclarationsErrors.ts, 6, 12)) + + }, + method2(p: I["readonlyType"]): I["readonlyType"] { +>method2 : Symbol(method2, Decl(uniqueSymbolsDeclarationsErrors.ts, 8, 6)) +>p : Symbol(p, Decl(uniqueSymbolsDeclarationsErrors.ts, 9, 12)) +>I : Symbol(I, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 31)) +>I : Symbol(I, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 31)) + + return p; +>p : Symbol(p, Decl(uniqueSymbolsDeclarationsErrors.ts, 9, 12)) + } +}; + +export const classExpression = class { +>classExpression : Symbol(classExpression, Decl(uniqueSymbolsDeclarationsErrors.ts, 14, 12)) + + method1(p: typeof s): typeof s { +>method1 : Symbol(classExpression.method1, Decl(uniqueSymbolsDeclarationsErrors.ts, 14, 38)) +>p : Symbol(p, Decl(uniqueSymbolsDeclarationsErrors.ts, 15, 12)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) + + return p; +>p : Symbol(p, Decl(uniqueSymbolsDeclarationsErrors.ts, 15, 12)) + } + method2(p: I["readonlyType"]): I["readonlyType"] { +>method2 : Symbol(classExpression.method2, Decl(uniqueSymbolsDeclarationsErrors.ts, 17, 5)) +>p : Symbol(p, Decl(uniqueSymbolsDeclarationsErrors.ts, 18, 12)) +>I : Symbol(I, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 31)) +>I : Symbol(I, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 31)) + + return p; +>p : Symbol(p, Decl(uniqueSymbolsDeclarationsErrors.ts, 18, 12)) + } +}; + +export function funcInferredReturnType(obj: { method(p: typeof s): void }) { +>funcInferredReturnType : Symbol(funcInferredReturnType, Decl(uniqueSymbolsDeclarationsErrors.ts, 21, 2)) +>obj : Symbol(obj, Decl(uniqueSymbolsDeclarationsErrors.ts, 23, 39)) +>method : Symbol(method, Decl(uniqueSymbolsDeclarationsErrors.ts, 23, 45)) +>p : Symbol(p, Decl(uniqueSymbolsDeclarationsErrors.ts, 23, 53)) +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) + + return obj; +>obj : Symbol(obj, Decl(uniqueSymbolsDeclarationsErrors.ts, 23, 39)) +} + +export interface InterfaceWithPrivateNamedProperties { +>InterfaceWithPrivateNamedProperties : Symbol(InterfaceWithPrivateNamedProperties, Decl(uniqueSymbolsDeclarationsErrors.ts, 25, 1)) + + [s]: any; +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +} + +export interface InterfaceWithPrivateNamedMethods { +>InterfaceWithPrivateNamedMethods : Symbol(InterfaceWithPrivateNamedMethods, Decl(uniqueSymbolsDeclarationsErrors.ts, 29, 1)) + + [s](): any; +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +} + +export type TypeLiteralWithPrivateNamedProperties = { +>TypeLiteralWithPrivateNamedProperties : Symbol(TypeLiteralWithPrivateNamedProperties, Decl(uniqueSymbolsDeclarationsErrors.ts, 33, 1)) + + [s]: any; +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +} + +export type TypeLiteralWithPrivateNamedMethods = { +>TypeLiteralWithPrivateNamedMethods : Symbol(TypeLiteralWithPrivateNamedMethods, Decl(uniqueSymbolsDeclarationsErrors.ts, 37, 1)) + + [s](): any; +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +} + +export class ClassWithPrivateNamedProperties { +>ClassWithPrivateNamedProperties : Symbol(ClassWithPrivateNamedProperties, Decl(uniqueSymbolsDeclarationsErrors.ts, 41, 1)) + + [s]: any; +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) + + static [s]: any; +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +} + +export class ClassWithPrivateNamedMethods { +>ClassWithPrivateNamedMethods : Symbol(ClassWithPrivateNamedMethods, Decl(uniqueSymbolsDeclarationsErrors.ts, 46, 1)) + + [s]() {} +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) + + static [s]() {} +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +} + +export class ClassWithPrivateNamedAccessors { +>ClassWithPrivateNamedAccessors : Symbol(ClassWithPrivateNamedAccessors, Decl(uniqueSymbolsDeclarationsErrors.ts, 51, 1)) + + get [s](): any { return undefined; } +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +>undefined : Symbol(undefined) + + set [s](v: any) { } +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +>v : Symbol(v, Decl(uniqueSymbolsDeclarationsErrors.ts, 55, 12)) + + static get [s](): any { return undefined; } +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +>undefined : Symbol(undefined) + + static set [s](v: any) { } +>s : Symbol(s, Decl(uniqueSymbolsDeclarationsErrors.ts, 0, 13)) +>v : Symbol(v, Decl(uniqueSymbolsDeclarationsErrors.ts, 57, 19)) +} diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.types b/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.types new file mode 100644 index 00000000000..ff3101193b4 --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.types @@ -0,0 +1,137 @@ +=== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts === +declare const s: unique symbol; +>s : unique symbol + +interface I { readonly readonlyType: unique symbol; } +>I : I +>readonlyType : unique symbol + +// not allowed when emitting declarations + +export const obj = { +>obj : { method1(p: unique symbol): unique symbol; method2(p: unique symbol): unique symbol; } +>{ method1(p: typeof s): typeof s { return p; }, method2(p: I["readonlyType"]): I["readonlyType"] { return p; }} : { method1(p: unique symbol): unique symbol; method2(p: unique symbol): unique symbol; } + + method1(p: typeof s): typeof s { +>method1 : (p: unique symbol) => unique symbol +>p : unique symbol +>s : unique symbol +>s : unique symbol + + return p; +>p : unique symbol + + }, + method2(p: I["readonlyType"]): I["readonlyType"] { +>method2 : (p: unique symbol) => unique symbol +>p : unique symbol +>I : I +>I : I + + return p; +>p : unique symbol + } +}; + +export const classExpression = class { +>classExpression : typeof classExpression +>class { method1(p: typeof s): typeof s { return p; } method2(p: I["readonlyType"]): I["readonlyType"] { return p; }} : typeof classExpression + + method1(p: typeof s): typeof s { +>method1 : (p: unique symbol) => unique symbol +>p : unique symbol +>s : unique symbol +>s : unique symbol + + return p; +>p : unique symbol + } + method2(p: I["readonlyType"]): I["readonlyType"] { +>method2 : (p: unique symbol) => unique symbol +>p : unique symbol +>I : I +>I : I + + return p; +>p : unique symbol + } +}; + +export function funcInferredReturnType(obj: { method(p: typeof s): void }) { +>funcInferredReturnType : (obj: { method(p: unique symbol): void; }) => { method(p: unique symbol): void; } +>obj : { method(p: unique symbol): void; } +>method : (p: unique symbol) => void +>p : unique symbol +>s : unique symbol + + return obj; +>obj : { method(p: unique symbol): void; } +} + +export interface InterfaceWithPrivateNamedProperties { +>InterfaceWithPrivateNamedProperties : InterfaceWithPrivateNamedProperties + + [s]: any; +>s : unique symbol +} + +export interface InterfaceWithPrivateNamedMethods { +>InterfaceWithPrivateNamedMethods : InterfaceWithPrivateNamedMethods + + [s](): any; +>s : unique symbol +} + +export type TypeLiteralWithPrivateNamedProperties = { +>TypeLiteralWithPrivateNamedProperties : TypeLiteralWithPrivateNamedProperties + + [s]: any; +>s : unique symbol +} + +export type TypeLiteralWithPrivateNamedMethods = { +>TypeLiteralWithPrivateNamedMethods : TypeLiteralWithPrivateNamedMethods + + [s](): any; +>s : unique symbol +} + +export class ClassWithPrivateNamedProperties { +>ClassWithPrivateNamedProperties : ClassWithPrivateNamedProperties + + [s]: any; +>s : unique symbol + + static [s]: any; +>s : unique symbol +} + +export class ClassWithPrivateNamedMethods { +>ClassWithPrivateNamedMethods : ClassWithPrivateNamedMethods + + [s]() {} +>s : unique symbol + + static [s]() {} +>s : unique symbol +} + +export class ClassWithPrivateNamedAccessors { +>ClassWithPrivateNamedAccessors : ClassWithPrivateNamedAccessors + + get [s](): any { return undefined; } +>s : unique symbol +>undefined : undefined + + set [s](v: any) { } +>s : unique symbol +>v : any + + static get [s](): any { return undefined; } +>s : unique symbol +>undefined : undefined + + static set [s](v: any) { } +>s : unique symbol +>v : any +} diff --git a/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts index a804ed8d20a..498a1c2904d 100644 --- a/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts +++ b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts @@ -1,6 +1,6 @@ // @target: esnext // @lib: esnext -// @declaration: true +// @declaration: false // declarations with call initializer const constCall = Symbol(); @@ -125,6 +125,7 @@ declare function g(x: typeof s): void; declare function g(x: typeof N.s): void; // widening positions + // argument inference f(s); f(N.s); @@ -135,11 +136,17 @@ f(N["s"]); [N.s]; [N["s"]]; -// property assignments +// property assignments/methods const o2 = { a: s, b: N.s, - c: N["s"] + c: N["s"], + + method1() { return s; }, + async method2() { return s; }, + async * method3() { yield s; }, + * method4() { yield s; }, + method5(p = s) { return p; }, }; // property initializers @@ -159,6 +166,12 @@ class C0 { d = s; e = N.s; f = N["s"]; + + method1() { return s; } + async method2() { return s; } + async * method3() { yield s; } + * method4() { yield s; } + method5(p = s) { return p; } } // non-widening positions @@ -198,4 +211,56 @@ class C1 { [s]: "a"; [N.s]: "b"; -} \ No newline at end of file +} + +// contextual types + +interface Context { + method1(): typeof s; + method2(): Promise; + method3(): AsyncIterableIterator; + method4(): IterableIterator; + method5(p?: typeof s): typeof s; +} + +const o3: Context = { + method1() { + return s; // return type should not widen due to contextual type + }, + async method2() { + return s; // return type should not widen due to contextual type + }, + async * method3() { + yield s; // yield type should not widen due to contextual type + }, + * method4() { + yield s; // yield type should not widen due to contextual type + }, + method5(p = s) { // parameter should not widen due to contextual type + return p; + }, +}; + +// allowed when not emitting declarations + +const o4 = { + method1(p: typeof s): typeof s { + return p; + }, + method2(p: I["readonlyType"]): I["readonlyType"] { + return p; + } +}; + +const ce0 = class { + method1(p: typeof s): typeof s { + return p; + } + method2(p: I["readonlyType"]): I["readonlyType"] { + return p; + } +}; + +function funcInferredReturnType(obj: { method(p: typeof s): void }) { + return obj; +} diff --git a/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarations.ts b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarations.ts new file mode 100644 index 00000000000..b097e290e8f --- /dev/null +++ b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarations.ts @@ -0,0 +1,242 @@ +// @target: esnext +// @lib: esnext +// @declaration: true + +// declarations with call initializer +const constCall = Symbol(); +let letCall = Symbol(); +var varCall = Symbol(); + +// ambient declaration with type +declare const constType: unique symbol; + +// declaration with type and call initializer +const constTypeAndCall: unique symbol = Symbol(); + +// declaration from initializer +const constInitToConstCall = constCall; +const constInitToLetCall = letCall; +const constInitToVarCall = varCall; +const constInitToConstDeclAmbient = constType; +let letInitToConstCall = constCall; +let letInitToLetCall = letCall; +let letInitToVarCall = varCall; +let letInitToConstDeclAmbient = constType; +var varInitToConstCall = constCall; +var varInitToLetCall = letCall; +var varInitToVarCall = varCall; +var varInitToConstDeclAmbient = constType; + +// declaration from initializer with type query +const constInitToConstCallWithTypeQuery: typeof constCall = constCall; +const constInitToConstDeclAmbientWithTypeQuery: typeof constType = constType; + +// function return inference +function funcReturnConstCall() { return constCall; } +function funcReturnLetCall() { return letCall; } +function funcReturnVarCall() { return varCall; } + +// function return value with type query +function funcReturnConstCallWithTypeQuery(): typeof constCall { return constCall; } + +// generator function yield inference +function* genFuncYieldConstCall() { yield constCall; } +function* genFuncYieldLetCall() { yield letCall; } +function* genFuncYieldVarCall() { yield varCall; } + +// generator function yield with return type query +function* genFuncYieldConstCallWithTypeQuery(): IterableIterator { yield constCall; } + +// async function return inference +async function asyncFuncReturnConstCall() { return constCall; } +async function asyncFuncReturnLetCall() { return letCall; } +async function asyncFuncReturnVarCall() { return varCall; } + +// async generator function yield inference +async function* asyncGenFuncYieldConstCall() { yield constCall; } +async function* asyncGenFuncYieldLetCall() { yield letCall; } +async function* asyncGenFuncYieldVarCall() { yield varCall; } + +// classes +class C { + static readonly readonlyStaticCall = Symbol(); + static readonly readonlyStaticType: unique symbol; + static readonly readonlyStaticTypeAndCall: unique symbol = Symbol(); + static readwriteStaticCall = Symbol(); + + readonly readonlyCall = Symbol(); + readwriteCall = Symbol(); +} +declare const c: C; + +const constInitToCReadonlyStaticCall = C.readonlyStaticCall; +const constInitToCReadonlyStaticType = C.readonlyStaticType; +const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; +const constInitToCReadwriteStaticCall = C.readwriteStaticCall; + +const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall = C.readonlyStaticCall; +const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType = C.readonlyStaticType; +const constInitToCReadonlyStaticTypeAndCallWithTypeQuery: typeof C.readonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; +const constInitToCReadwriteStaticCallWithTypeQuery: typeof C.readwriteStaticCall = C.readwriteStaticCall; + +const constInitToCReadonlyCall = c.readonlyCall; +const constInitToCReadwriteCall = c.readwriteCall; +const constInitToCReadonlyCallWithTypeQuery: typeof c.readonlyCall = c.readonlyCall; +const constInitToCReadwriteCallWithTypeQuery: typeof c.readwriteCall = c.readwriteCall; +const constInitToCReadonlyCallWithIndexedAccess: C["readonlyCall"] = c.readonlyCall; +const constInitToCReadwriteCallWithIndexedAccess: C["readwriteCall"] = c.readwriteCall; + +// interfaces +interface I { + readonly readonlyType: unique symbol; +} +declare const i: I; + +const constInitToIReadonlyType = i.readonlyType; +const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType = i.readonlyType; +const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"] = i.readonlyType; + +// type literals +type L = { + readonly readonlyType: unique symbol; + nested: { + readonly readonlyNestedType: unique symbol; + } +}; +declare const l: L; + +const constInitToLReadonlyType = l.readonlyType; +const constInitToLReadonlyNestedType = l.nested.readonlyNestedType; +const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType = l.readonlyType; +const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType = l.nested.readonlyNestedType; +const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"] = l.readonlyType; +const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"] = l.nested.readonlyNestedType; + +// type argument inference +const promiseForConstCall = Promise.resolve(constCall); +const arrayOfConstCall = [constCall]; + +// unique symbol widening in expressions +declare const s: unique symbol; +declare namespace N { const s: unique symbol; } +declare const o: { [s]: "a", [N.s]: "b" }; +declare function f(x: T): T; +declare function g(x: typeof s): void; +declare function g(x: typeof N.s): void; + +// widening positions + +// argument inference +f(s); +f(N.s); +f(N["s"]); + +// array literal elements +[s]; +[N.s]; +[N["s"]]; + +// property assignments/methods +const o2 = { + a: s, + b: N.s, + c: N["s"], + + method1() { return s; }, + async method2() { return s; }, + async * method3() { yield s; }, + * method4() { yield s; }, + method5(p = s) { return p; } +}; + +// property initializers +class C0 { + static readonly a = s; + static readonly b = N.s; + static readonly c = N["s"]; + + static d = s; + static e = N.s; + static f = N["s"]; + + readonly a = s; + readonly b = N.s; + readonly c = N["s"]; + + d = s; + e = N.s; + f = N["s"]; + + method1() { return s; } + async method2() { return s; } + async * method3() { yield s; } + * method4() { yield s; } + method5(p = s) { return p; } +} + +// non-widening positions + +// element access +o[s]; +o[N.s]; +o[N["s"]]; + +// arguments (no-inference) +f(s); +f(N.s); +f(N["s"]); +g(s); +g(N.s); +g(N["s"]); + +// falsy expressions +s || ""; +N.s || ""; +N["s"] || ""; + +// conditionals +Math.random() * 2 ? s : "a"; +Math.random() * 2 ? N.s : "a"; +Math.random() * 2 ? N["s"] : "a"; + +// computed property names +({ + [s]: "a", + [N.s]: "b", +}); + +class C1 { + static [s]: "a"; + static [N.s]: "b"; + + [s]: "a"; + [N.s]: "b"; +} + +// contextual types + +interface Context { + method1(): typeof s; + method2(): Promise; + method3(): AsyncIterableIterator; + method4(): IterableIterator; + method5(p?: typeof s): typeof s; +} + +const o4: Context = { + method1() { + return s; // return type should not widen due to contextual type + }, + async method2() { + return s; // return type should not widen due to contextual type + }, + async * method3() { + yield s; // yield type should not widen due to contextual type + }, + * method4() { + yield s; // yield type should not widen due to contextual type + }, + method5(p = s) { // parameter should not widen due to contextual type + return p; + } +}; \ No newline at end of file diff --git a/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts new file mode 100644 index 00000000000..227dbd9c90d --- /dev/null +++ b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsErrors.ts @@ -0,0 +1,64 @@ +// @target: esnext +// @lib: esnext +// @module: commonjs +// @declaration: true + +declare const s: unique symbol; +interface I { readonly readonlyType: unique symbol; } + +// not allowed when emitting declarations + +export const obj = { + method1(p: typeof s): typeof s { + return p; + }, + method2(p: I["readonlyType"]): I["readonlyType"] { + return p; + } +}; + +export const classExpression = class { + method1(p: typeof s): typeof s { + return p; + } + method2(p: I["readonlyType"]): I["readonlyType"] { + return p; + } +}; + +export function funcInferredReturnType(obj: { method(p: typeof s): void }) { + return obj; +} + +export interface InterfaceWithPrivateNamedProperties { + [s]: any; +} + +export interface InterfaceWithPrivateNamedMethods { + [s](): any; +} + +export type TypeLiteralWithPrivateNamedProperties = { + [s]: any; +} + +export type TypeLiteralWithPrivateNamedMethods = { + [s](): any; +} + +export class ClassWithPrivateNamedProperties { + [s]: any; + static [s]: any; +} + +export class ClassWithPrivateNamedMethods { + [s]() {} + static [s]() {} +} + +export class ClassWithPrivateNamedAccessors { + get [s](): any { return undefined; } + set [s](v: any) { } + static get [s](): any { return undefined; } + static set [s](v: any) { } +} \ No newline at end of file