Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
311a0cf
Added tests.
DanielRosenwasser Sep 11, 2015
911e907
Added test for string literal types in type arguments.
DanielRosenwasser Oct 1, 2015
f04cc39
Accepted baselines.
DanielRosenwasser Oct 1, 2015
191be4f
Make string literals valid constituent types nodes in the parser.
DanielRosenwasser Oct 1, 2015
84786d8
Accepted baselines.
DanielRosenwasser Oct 1, 2015
dc0e368
Make string literals valid types in type lists.
DanielRosenwasser Oct 1, 2015
8891fba
Accepted baselines.
DanielRosenwasser Oct 1, 2015
82545ce
Added test for string types in tuples.
DanielRosenwasser Oct 1, 2015
ed927d8
Accepted baselines.
DanielRosenwasser Oct 1, 2015
a3e7ccb
Use normalized text for text on string literal types.
DanielRosenwasser Oct 2, 2015
20c2c4e
Amended fourslash tests to expect double quotes.
DanielRosenwasser Oct 2, 2015
87f2957
Accepted baselines.
DanielRosenwasser Oct 2, 2015
f721971
Capture compatible contextual types for unions containing string lite…
DanielRosenwasser Oct 2, 2015
7b4e94d
Accepted baselines.
DanielRosenwasser Oct 2, 2015
d8d72aa
Separated the concept of apparent types from contextual types for str…
DanielRosenwasser Oct 2, 2015
315b06d
Accepted baselines.
DanielRosenwasser Oct 2, 2015
4b736da
Fixed issue in test.
DanielRosenwasser Oct 2, 2015
fd5dec4
Accepted baselines.
DanielRosenwasser Oct 2, 2015
f7a6ac7
Added more tests.
DanielRosenwasser Oct 7, 2015
a440f06
Accepted baselines.
DanielRosenwasser Oct 8, 2015
d2e2a55
Added fourslash test.
DanielRosenwasser Oct 8, 2015
6e3343c
Merge branch 'master' into stringLiteralTypes
DanielRosenwasser Oct 8, 2015
74ac57d
Accepted post-merge baselines.
DanielRosenwasser Oct 8, 2015
61ece76
Return the string literal type itself instead of the union type.
DanielRosenwasser Oct 8, 2015
84b64c4
Accepted baselines.
DanielRosenwasser Oct 8, 2015
3788254
Semicolon.
DanielRosenwasser Oct 8, 2015
ebc47d5
Linting.
DanielRosenwasser Oct 8, 2015
725bda8
Merge branch 'master' into stringLiteralTypes
DanielRosenwasser Oct 15, 2015
ec0d49a
Always use a string literal type if contextually typed by any string …
DanielRosenwasser Oct 15, 2015
1dbd8d1
Accepted baselines.
DanielRosenwasser Oct 15, 2015
307d73e
Merge branch 'master' into stringLiteralTypes
DanielRosenwasser Oct 22, 2015
049d02f
Merge branch 'master' into stringLiteralTypes
DanielRosenwasser Oct 23, 2015
6618fd2
Added tests for operations that use assignable to/from.
DanielRosenwasser Oct 26, 2015
bf4880a
Merge branch 'master' into stringLiteralTypes
DanielRosenwasser Oct 26, 2015
5e23143
Accepted baselines.
DanielRosenwasser Oct 27, 2015
8dbfe1c
Added specific checks for comparing stringlike types.
DanielRosenwasser Nov 6, 2015
a1fcfaf
Accepted baselines.
DanielRosenwasser Nov 6, 2015
bb232f7
Merge remote-tracking branch 'origin/master' into stringLiteralTypes
DanielRosenwasser Nov 6, 2015
f939ff2
Fixed unreachable code in tests.
DanielRosenwasser Nov 6, 2015
d234b8d
Accepted baselines.
DanielRosenwasser Nov 6, 2015
c011ed4
Const.
DanielRosenwasser Nov 6, 2015
38090c6
Added tests for template strings with string literal types.
DanielRosenwasser Nov 9, 2015
d294524
Accepted baselines.
DanielRosenwasser Nov 9, 2015
ea4e21d
Fixed comments.
DanielRosenwasser Nov 9, 2015
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
Prev Previous commit
Next Next commit
Accepted baselines.
  • Loading branch information
DanielRosenwasser committed Oct 2, 2015
commit 315b06dc99b6bcf6079e31f535d9ab3171d1d9ad
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ b('foo').charAt(0);
>b('foo').charAt : (pos: number) => string
>b('foo') : string
>b : B
>'foo' : string
>'foo' : "foo"
>charAt : (pos: number) => string
>0 : number

Expand Down Expand Up @@ -94,25 +94,25 @@ var x1: string[] = c('B2');
>x1 : string[]
>c('B2') : string[]
>c : C
>'B2' : string
>'B2' : "B2"

var x2: number = c('B1');
>x2 : number
>c('B1') : number
>c : C
>'B1' : string
>'B1' : "B1"

var x3: boolean = c('A2');
>x3 : boolean
>c('A2') : boolean
>c : C
>'A2' : string
>'A2' : "A2"

var x4: string = c('A1');
>x4 : string
>c('A1') : string
>c : C
>'A1' : string
>'A1' : "A1"

var x5: void = c('A0');
>x5 : void
Expand All @@ -124,19 +124,19 @@ var x6: number[] = c('C1');
>x6 : number[]
>c('C1') : number[]
>c : C
>'C1' : string
>'C1' : "C1"

var x7: boolean[] = c('C2');
>x7 : boolean[]
>c('C2') : boolean[]
>c : C
>'C2' : string
>'C2' : "C2"

var x8: string = c('C');
>x8 : string
>c('C') : string
>c : C
>'C' : string
>'C' : "C"

var x9: void = c('generic');
>x9 : void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var r = f('a');
>r : number
>f('a') : number
>f : Foo
>'a' : string
>'a' : "a"

var r2 = f('A');
>r2 : any
Expand All @@ -36,7 +36,7 @@ var r3 = new f('a');
>r3 : any
>new f('a') : any
>f : Foo
>'a' : string
>'a' : "a"

var r4 = new f('A');
>r4 : Object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndTuples01.ts(6,5): error TS2322: Type '[string, string, string]' is not assignable to type '["I'm", "a", any]'.
Types of property '0' are incompatible.
Type 'string' is not assignable to type '"I'm"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndTuples01.ts(6,37): error TS2304: Cannot find name 'Dinosaur'.


==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndTuples01.ts (2 errors) ====
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndTuples01.ts (1 errors) ====

// Should all be strings.
let [hello, brave, newish, world] = ["Hello", "Brave", "New", "World"];

type RexOrRaptor = "t-rex" | "raptor"
let [im, a, dinosaur]: ["I'm", "a", Dinosaur] = ['I\'m', 'a', 't-rex'];
~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '[string, string, string]' is not assignable to type '["I'm", "a", any]'.
!!! error TS2322: Types of property '0' are incompatible.
!!! error TS2322: Type 'string' is not assignable to type '"I'm"'.
~~~~~~~~
!!! error TS2304: Cannot find name 'Dinosaur'.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(18,10)
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(19,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(20,10): error TS2394: Overload signature is not compatible with function implementation.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(22,21): error TS2304: Cannot find name 'is'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(25,5): error TS2322: Type '{ kind: string; a: number; }' is not assignable to type 'A'.
Types of property 'kind' are incompatible.
Type 'string' is not assignable to type '"A"'.


==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts (5 errors) ====
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts (4 errors) ====

type Kind = "A" | "B"

Expand Down Expand Up @@ -41,10 +38,6 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(25,5):
}

let x: A = {
~
!!! error TS2322: Type '{ kind: string; a: number; }' is not assignable to type 'A'.
!!! error TS2322: Types of property 'kind' are incompatible.
!!! error TS2322: Type 'string' is not assignable to type '"A"'.
kind: "A",
a: 100,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(5,7): error TS1155: 'const' declarations must be initialized
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(7,1): error TS2322: Type 'string' is not assignable to type '""'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(8,1): error TS2322: Type 'string' is not assignable to type '"foo"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(9,1): error TS2322: Type 'string' is not assignable to type '"bar"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(11,5): error TS2322: Type 'string' is not assignable to type '""'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(12,5): error TS2322: Type 'string' is not assignable to type '"foo"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(13,5): error TS2322: Type 'string' is not assignable to type '"bar"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(14,7): error TS2322: Type 'string' is not assignable to type '"baz"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(16,1): error TS2322: Type 'string' is not assignable to type '""'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(17,1): error TS2322: Type 'string' is not assignable to type '"foo"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(18,1): error TS2322: Type 'string' is not assignable to type '"bar"'.


==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts (11 errors) ====
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts (1 errors) ====

let a: "";
var b: "foo";
Expand All @@ -21,34 +11,14 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarat
!!! error TS1155: 'const' declarations must be initialized

a = "";
~
!!! error TS2322: Type 'string' is not assignable to type '""'.
b = "foo";
~
!!! error TS2322: Type 'string' is not assignable to type '"foo"'.
c = "bar";
~
!!! error TS2322: Type 'string' is not assignable to type '"bar"'.

let e: "" = "";
~
!!! error TS2322: Type 'string' is not assignable to type '""'.
var f: "foo" = "foo";
~
!!! error TS2322: Type 'string' is not assignable to type '"foo"'.
let g: "bar" = "bar";
~
!!! error TS2322: Type 'string' is not assignable to type '"bar"'.
const h: "baz" = "baz";
~
!!! error TS2322: Type 'string' is not assignable to type '"baz"'.

e = "";
~
!!! error TS2322: Type 'string' is not assignable to type '""'.
f = "foo";
~
!!! error TS2322: Type 'string' is not assignable to type '"foo"'.
g = "bar";
~
!!! error TS2322: Type 'string' is not assignable to type '"bar"'.
g = "bar";
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(11,10): error TS2354: No best common type exists among return expressions.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(32,7): error TS2322: Type 'string' is not assignable to type '"string"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(33,7): error TS2322: Type 'string' is not assignable to type '"number"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(34,7): error TS2322: Type 'string' is not assignable to type '"boolean"'.


==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts (4 errors) ====
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts (1 errors) ====

type PrimitiveName = 'string' | 'number' | 'boolean';

Expand Down Expand Up @@ -39,14 +36,8 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(34,
}

const string: "string" = "string"
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type '"string"'.
const number: "number" = "number"
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type '"number"'.
const boolean: "boolean" = "boolean"
~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type '"boolean"'.

const stringOrNumber = string || number;
const stringOrBoolean = string || boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(9,10): error TS2354: No best common type exists among return expressions.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(30,7): error TS2322: Type 'string' is not assignable to type '"string"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(31,7): error TS2322: Type 'string' is not assignable to type '"number"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(32,7): error TS2322: Type 'string' is not assignable to type '"boolean"'.


==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts (4 errors) ====
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts (1 errors) ====

function getFalsyPrimitive(x: "string"): string;
function getFalsyPrimitive(x: "number"): number;
Expand Down Expand Up @@ -37,14 +34,8 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(32,
}

const string: "string" = "string"
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type '"string"'.
const number: "number" = "number"
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type '"number"'.
const boolean: "boolean" = "boolean"
~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type '"boolean"'.

const stringOrNumber = string || number;
const stringOrBoolean = string || boolean;
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/symbolProperty41.types
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ c[Symbol.iterator]("hello");
>Symbol.iterator : symbol
>Symbol : SymbolConstructor
>iterator : symbol
>"hello" : string
>"hello" : "hello"

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0
Type 'string' is not assignable to type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(48,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
Type 'string' is not assignable to type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(55,34): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(57,43): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(58,34): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(55,43): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(57,52): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(58,43): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(61,5): error TS2322: Type 'string' is not assignable to type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(63,5): error TS2322: Type 'string' is not assignable to type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(75,5): error TS2322: Type '"Hello" | "World"' is not assignable to type '"Hello"'.
Expand All @@ -25,7 +25,7 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0
Type '"World"' is not assignable to type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(87,43): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(88,43): error TS2345: Argument of type 'string' is not assignable to parameter of type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(89,43): error TS2345: Argument of type 'string' is not assignable to parameter of type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(89,52): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(93,5): error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'.
Type 'string' is not assignable to type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(97,5): error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'.
Expand Down Expand Up @@ -119,14 +119,14 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0
// as "Hello" (or "Hello" | "Hello").
export let a = fun1<"Hello">("Hello", "Hello");
export let b = fun1<"Hello">("Hello", "World");
~~~~~~~
~~~~~~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
export let c = fun2<"Hello", "Hello">("Hello", "Hello");
export let d = fun2<"Hello", "Hello">("Hello", "World");
~~~~~~~
~~~~~~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
export let e = fun3<"Hello">("Hello", "World");
~~~~~~~
~~~~~~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.

// Assignment from the returned value should cause an error.
Expand Down Expand Up @@ -173,8 +173,8 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0
~~~~~~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"World"'.
export let d = fun2<"World", "Hello">("World", "World");
~~~~~~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"World"'.
~~~~~~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
export let e = fun3<"Hello" | "World">("Hello", "World");

// Assignment from the returned value should cause an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var r1: Derived1 = c.foo('hi');
>c.foo : { (x: "hi"): Derived1; (x: "bye"): Derived2; (x: string): Base; }
>c : C
>foo : { (x: "hi"): Derived1; (x: "bye"): Derived2; (x: string): Base; }
>'hi' : string
>'hi' : "hi"

var r2: Derived2 = c.foo('bye');
>r2 : Derived2
Expand All @@ -134,7 +134,7 @@ var r2: Derived2 = c.foo('bye');
>c.foo : { (x: "hi"): Derived1; (x: "bye"): Derived2; (x: string): Base; }
>c : C
>foo : { (x: "hi"): Derived1; (x: "bye"): Derived2; (x: string): Base; }
>'bye' : string
>'bye' : "bye"

var r3: Base = c.foo('hm');
>r3 : Base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ var r1 = new C('hi');
>r1 : C
>new C('hi') : C
>C : typeof C
>'hi' : string
>'hi' : "hi"

var r2: Derived2 = new i('bye');
>r2 : Derived2
>Derived2 : Derived2
>new i('bye') : Derived2
>i : I
>'bye' : string
>'bye' : "bye"

var r3: Base = new a('hm');
>r3 : Base
Expand Down