TypeScript/tests/baselines/reference/subtypesOfUnion.types

162 lines
2.5 KiB
Plaintext

=== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts ===
enum E { e1, e2 }
>E : E
>e1 : E.e1
>e2 : E.e2
interface I8 { [x: string]: number[]; }
>x : string
class A { foo: number; }
>A : A
>foo : number
class A2<T> { foo: T; }
>A2 : A2<T>
>foo : T
function f() { }
>f : typeof f
module f { export var bar = 1; }
>f : typeof f
>bar : number
>1 : 1
class c { baz: string }
>c : c
>baz : string
module c { export var bar = 1; }
>c : typeof c
>bar : number
>1 : 1
// A type T is a subtype of a union type U if T is a subtype of any type in U.
interface I1<T> {
[x: string]: string | number;
>x : string
foo: any; // ok
>foo : any
foo2: string; // ok
>foo2 : string
foo3: number; // ok
>foo3 : number
foo4: boolean; // error
>foo4 : boolean
foo5: E; // ok - subtype of number
>foo5 : E
foo6: Date; // error
>foo6 : Date
foo7: RegExp; // error
>foo7 : RegExp
foo8: { bar: number }; // error
>foo8 : { bar: number; }
>bar : number
foo9: I8; // error
>foo9 : I8
foo10: A; // error
>foo10 : A
foo11: A2<number>; // error
>foo11 : A2<number>
foo12: (x) => number; //error
>foo12 : (x: any) => number
>x : any
foo13: <T>(x: T) => T; // error
>foo13 : <T>(x: T) => T
>x : T
foo14: typeof f; // error
>foo14 : typeof f
>f : typeof f
foo15: typeof c; // error
>foo15 : typeof c
>c : typeof c
foo16: T; // error
>foo16 : T
foo17: Object; // error
>foo17 : Object
foo18: {}; // error
>foo18 : {}
}
interface I2<T> {
[x: string]: E | number;
>x : string
foo: any; // ok
>foo : any
foo2: string; // error
>foo2 : string
foo3: number; // ok
>foo3 : number
foo4: boolean; // error
>foo4 : boolean
foo5: E; // ok
>foo5 : E
foo6: Date; // error
>foo6 : Date
foo7: RegExp; // error
>foo7 : RegExp
foo8: { bar: number }; // error
>foo8 : { bar: number; }
>bar : number
foo9: I8; // error
>foo9 : I8
foo10: A; // error
>foo10 : A
foo11: A2<number>; // error
>foo11 : A2<number>
foo12: (x) => number; //error
>foo12 : (x: any) => number
>x : any
foo13: <T>(x: T) => T; // error
>foo13 : <T>(x: T) => T
>x : T
foo14: typeof f; // error
>foo14 : typeof f
>f : typeof f
foo15: typeof c; // error
>foo15 : typeof c
>c : typeof c
foo16: T; // error
>foo16 : T
foo17: Object; // error
>foo17 : Object
foo18: {}; // error
>foo18 : {}
}