Merge pull request #21585 from Microsoft/fix21584

Fix initializer assignability for unique symbol
This commit is contained in:
Ron Buckton
2018-02-06 11:30:12 -08:00
committed by GitHub
7 changed files with 29 additions and 9 deletions

View File

@@ -8418,7 +8418,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;
}

View File

@@ -3311,6 +3311,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)
outerTypeParameters?: TypeParameter[]; // Outer type parameters of anonymous object type

View File

@@ -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;
~~~~~~
@@ -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'.

View File

@@ -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
@@ -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();

View File

@@ -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, --, --))

View File

@@ -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

View File

@@ -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();