Skip to content

Fix initializer assignability for unique symbol #21585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8249,7 +8249,7 @@ namespace ts {
if (isValidESSymbolDeclaration(node)) {
const symbol = getSymbolOfNode(node);
const links = getSymbolLinks(symbol);
return links.type || (links.type = createUniqueESSymbolType(symbol));
return links.uniqueESSymbolType || (links.uniqueESSymbolType = createUniqueESSymbolType(symbol));
}
return esSymbolType;
}
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3294,6 +3294,7 @@ namespace ts {
immediateTarget?: Symbol; // Immediate target of an alias. May be another alias. Do not access directly, use `checker.getImmediateAliasedSymbol` instead.
target?: Symbol; // Resolved (non-alias) target of an alias
type?: Type; // Type of value symbol
uniqueESSymbolType?: Type; // UniqueESSymbol type for a symbol
declaredType?: Type; // Type of class, interface, enum, type alias, or type parameter
typeParameters?: TypeParameter[]; // Type parameters of type alias (undefined if non-generic)
inferredClassType?: Type; // Type of an inferred ES5 class
Expand Down
10 changes: 7 additions & 3 deletions tests/baselines/reference/uniqueSymbolsErrors.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsErrors.ts(82,29): error
tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsErrors.ts(82,45): error TS1335: 'unique symbol' types are not allowed here.
tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsErrors.ts(83,36): error TS1335: 'unique symbol' types are not allowed here.
tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsErrors.ts(83,52): error TS1335: 'unique symbol' types are not allowed here.
tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsErrors.ts(87,7): error TS2322: Type 'unique symbol' is not assignable to type 'string'.


==== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsErrors.ts (60 errors) ====
==== tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsErrors.ts (61 errors) ====
// declarations
declare const invalidUniqueType: unique number;
~~~~~~
Expand Down Expand Up @@ -265,5 +266,8 @@ tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsErrors.ts(83,52): error
~~~~~~~~~~~~~
!!! error TS1335: 'unique symbol' types are not allowed here.



// initializer assignability
// https://github.com/Microsoft/TypeScript/issues/21584
const shouldNotBeAssignable: string = Symbol();
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'unique symbol' is not assignable to type 'string'.
8 changes: 6 additions & 2 deletions tests/baselines/reference/uniqueSymbolsErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ declare const invalidMappedType: { [P in string]: unique symbol };
declare const invalidUnion: unique symbol | unique symbol;
declare const invalidIntersection: unique symbol | unique symbol;



// initializer assignability
// https://github.com/Microsoft/TypeScript/issues/21584
const shouldNotBeAssignable: string = Symbol();

//// [uniqueSymbolsErrors.js]
// classes
Expand All @@ -109,3 +110,6 @@ class InvalidClass {
static get invalidStaticGetter() { return; }
static set invalidStaticSetter(arg) { return; }
}
// initializer assignability
// https://github.com/Microsoft/TypeScript/issues/21584
const shouldNotBeAssignable = Symbol();
6 changes: 5 additions & 1 deletion tests/baselines/reference/uniqueSymbolsErrors.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,9 @@ declare const invalidUnion: unique symbol | unique symbol;
declare const invalidIntersection: unique symbol | unique symbol;
>invalidIntersection : Symbol(invalidIntersection, Decl(uniqueSymbolsErrors.ts, 82, 13))


// initializer assignability
// https://github.com/Microsoft/TypeScript/issues/21584
const shouldNotBeAssignable: string = Symbol();
>shouldNotBeAssignable : Symbol(shouldNotBeAssignable, Decl(uniqueSymbolsErrors.ts, 86, 5))
>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --))

7 changes: 6 additions & 1 deletion tests/baselines/reference/uniqueSymbolsErrors.types
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,10 @@ declare const invalidUnion: unique symbol | unique symbol;
declare const invalidIntersection: unique symbol | unique symbol;
>invalidIntersection : symbol


// initializer assignability
// https://github.com/Microsoft/TypeScript/issues/21584
const shouldNotBeAssignable: string = Symbol();
>shouldNotBeAssignable : string
>Symbol() : unique symbol
>Symbol : SymbolConstructor

Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ declare const invalidMappedType: { [P in string]: unique symbol };
declare const invalidUnion: unique symbol | unique symbol;
declare const invalidIntersection: unique symbol | unique symbol;


// initializer assignability
// https://github.com/Microsoft/TypeScript/issues/21584
const shouldNotBeAssignable: string = Symbol();