Tests for union type literals
A union type literal is written as a sequence of types separated by vertical bars. UnionType: PrimaryOrUnionType | PrimaryType A union typle literal references a union type. When function or constructor types are included in union types they must be enclosed in parentheses
This commit is contained in:
parent
24ebc750c0
commit
16fc7a22e2
3 changed files with 78 additions and 0 deletions
29
tests/baselines/reference/unionTypeLiterals.js
Normal file
29
tests/baselines/reference/unionTypeLiterals.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
//// [unionTypeLiterals.ts]
|
||||
// basic valid forms of union literals
|
||||
|
||||
var simpleUnion: string | number;
|
||||
var unionOfUnion: string | number | boolean;
|
||||
|
||||
var arrayOfUnions: (string | number)[];
|
||||
var arrayOfUnions: Array<string | number>;
|
||||
|
||||
var unionOfFunctionType: (() => string) | (() => number);
|
||||
var unionOfFunctionType: { (): string } | { (): number };
|
||||
var unionOfFunctionType: () => string | number;
|
||||
|
||||
var unionOfConstructorType: (new () => string) | (new () => number);
|
||||
var unionOfConstructorType: { new (): string } | { new (): number };
|
||||
var unionOfConstructorType: new () => string | number;
|
||||
|
||||
//// [unionTypeLiterals.js]
|
||||
// basic valid forms of union literals
|
||||
var simpleUnion;
|
||||
var unionOfUnion;
|
||||
var arrayOfUnions;
|
||||
var arrayOfUnions;
|
||||
var unionOfFunctionType;
|
||||
var unionOfFunctionType;
|
||||
var unionOfFunctionType;
|
||||
var unionOfConstructorType;
|
||||
var unionOfConstructorType;
|
||||
var unionOfConstructorType;
|
34
tests/baselines/reference/unionTypeLiterals.types
Normal file
34
tests/baselines/reference/unionTypeLiterals.types
Normal file
|
@ -0,0 +1,34 @@
|
|||
=== tests/cases/conformance/types/specifyingTypes/typeLiterals/unionTypeLiterals.ts ===
|
||||
// basic valid forms of union literals
|
||||
|
||||
var simpleUnion: string | number;
|
||||
>simpleUnion : string | number
|
||||
|
||||
var unionOfUnion: string | number | boolean;
|
||||
>unionOfUnion : string | number | boolean
|
||||
|
||||
var arrayOfUnions: (string | number)[];
|
||||
>arrayOfUnions : (string | number)[]
|
||||
|
||||
var arrayOfUnions: Array<string | number>;
|
||||
>arrayOfUnions : (string | number)[]
|
||||
>Array : T[]
|
||||
|
||||
var unionOfFunctionType: (() => string) | (() => number);
|
||||
>unionOfFunctionType : (() => string) | (() => number)
|
||||
|
||||
var unionOfFunctionType: { (): string } | { (): number };
|
||||
>unionOfFunctionType : (() => string) | (() => number)
|
||||
|
||||
var unionOfFunctionType: () => string | number;
|
||||
>unionOfFunctionType : (() => string) | (() => number)
|
||||
|
||||
var unionOfConstructorType: (new () => string) | (new () => number);
|
||||
>unionOfConstructorType : (new () => string) | (new () => number)
|
||||
|
||||
var unionOfConstructorType: { new (): string } | { new (): number };
|
||||
>unionOfConstructorType : (new () => string) | (new () => number)
|
||||
|
||||
var unionOfConstructorType: new () => string | number;
|
||||
>unionOfConstructorType : (new () => string) | (new () => number)
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
// basic valid forms of union literals
|
||||
|
||||
var simpleUnion: string | number;
|
||||
var unionOfUnion: string | number | boolean;
|
||||
|
||||
var arrayOfUnions: (string | number)[];
|
||||
var arrayOfUnions: Array<string | number>;
|
||||
|
||||
var unionOfFunctionType: (() => string) | (() => number);
|
||||
var unionOfFunctionType: { (): string } | { (): number };
|
||||
var unionOfFunctionType: () => string | number;
|
||||
|
||||
var unionOfConstructorType: (new () => string) | (new () => number);
|
||||
var unionOfConstructorType: { new (): string } | { new (): number };
|
||||
var unionOfConstructorType: new () => string | number;
|
Loading…
Reference in a new issue