mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 06:41:59 -06:00
Unescape string literal types starting with double underscore.
String literal types starting with double underscore are escaped in the parser and need to be unescaped before the type is given the string literal as its name.
This commit is contained in:
parent
3fb16f5930
commit
e25927da57
@ -5138,12 +5138,13 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getStringLiteralTypeForText(text: string): StringLiteralType {
|
||||
if (hasProperty(stringLiteralTypes, text)) {
|
||||
return stringLiteralTypes[text];
|
||||
const unescaped = unescapeIdentifier(text);
|
||||
if (hasProperty(stringLiteralTypes, unescaped)) {
|
||||
return stringLiteralTypes[unescaped];
|
||||
}
|
||||
|
||||
const type = stringLiteralTypes[text] = <StringLiteralType>createType(TypeFlags.StringLiteral);
|
||||
type.text = text;
|
||||
const type = stringLiteralTypes[unescaped] = <StringLiteralType>createType(TypeFlags.StringLiteral);
|
||||
type.text = unescaped;
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
tests/cases/compiler/doubleUnderStringLiteralAssignability.ts(2,5): error TS2322: Type '"no_dunder"' is not assignable to type '"__dunder"'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/doubleUnderStringLiteralAssignability.ts (1 errors) ====
|
||||
var shouldBeOk: '__dunder' = '__dunder';
|
||||
var bad: '__dunder' = 'no_dunder';
|
||||
~~~
|
||||
!!! error TS2322: Type '"no_dunder"' is not assignable to type '"__dunder"'.
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
//// [doubleUnderStringLiteralAssignability.ts]
|
||||
var shouldBeOk: '__dunder' = '__dunder';
|
||||
var bad: '__dunder' = 'no_dunder';
|
||||
|
||||
|
||||
//// [doubleUnderStringLiteralAssignability.js]
|
||||
var shouldBeOk = '__dunder';
|
||||
var bad = 'no_dunder';
|
||||
@ -0,0 +1,2 @@
|
||||
var shouldBeOk: '__dunder' = '__dunder';
|
||||
var bad: '__dunder' = 'no_dunder';
|
||||
Loading…
x
Reference in New Issue
Block a user