mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-28 15:06:29 -05:00
Add more tests
This commit is contained in:
129
tests/baselines/reference/mappedTypes4.js
Normal file
129
tests/baselines/reference/mappedTypes4.js
Normal file
@@ -0,0 +1,129 @@
|
||||
//// [mappedTypes4.ts]
|
||||
|
||||
type Box<T> = {
|
||||
};
|
||||
|
||||
type Boxified<T> = {
|
||||
[P in keyof T]: Box<T[P]>;
|
||||
};
|
||||
|
||||
function boxify<T>(obj: T): Boxified<T> {
|
||||
if (typeof obj === "object") {
|
||||
let result = {} as Boxified<T>;
|
||||
for (let k in obj) {
|
||||
result[k] = { value: obj[k] };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return <any>obj;
|
||||
}
|
||||
|
||||
type A = { a: string };
|
||||
type B = { b: string };
|
||||
type C = { c: string };
|
||||
|
||||
function f1(x: A | B | C | undefined) {
|
||||
return boxify(x);
|
||||
}
|
||||
|
||||
type T00 = Partial<A | B | C>;
|
||||
type T01 = Readonly<A | B | C | null | undefined>;
|
||||
type T02 = Boxified<A | B[] | C | string>
|
||||
type T03 = Readonly<string | number | boolean | null | undefined | void>;
|
||||
type T04 = Boxified<string | number | boolean | null | undefined | void>;
|
||||
type T05 = Partial<"hello" | "world" | 42>;
|
||||
|
||||
type BoxifiedWithSentinel<T, U> = {
|
||||
[P in keyof T]: Box<T[P]> | U;
|
||||
}
|
||||
|
||||
type T10 = BoxifiedWithSentinel<A | B | C, null>;
|
||||
type T11 = BoxifiedWithSentinel<A | B | C, undefined>;
|
||||
type T12 = BoxifiedWithSentinel<string, undefined>;
|
||||
|
||||
type DeepReadonly<T> = {
|
||||
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
x: number;
|
||||
y: { a: string, b: number };
|
||||
z: boolean;
|
||||
};
|
||||
|
||||
type DeepReadonlyFoo = {
|
||||
readonly x: number;
|
||||
readonly y: { readonly a: string, readonly b: number };
|
||||
readonly z: boolean;
|
||||
};
|
||||
|
||||
var x1: DeepReadonly<Foo>;
|
||||
var x1: DeepReadonlyFoo;
|
||||
|
||||
//// [mappedTypes4.js]
|
||||
function boxify(obj) {
|
||||
if (typeof obj === "object") {
|
||||
var result = {};
|
||||
for (var k in obj) {
|
||||
result[k] = { value: obj[k] };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
function f1(x) {
|
||||
return boxify(x);
|
||||
}
|
||||
var x1;
|
||||
var x1;
|
||||
|
||||
|
||||
//// [mappedTypes4.d.ts]
|
||||
declare type Box<T> = {};
|
||||
declare type Boxified<T> = {
|
||||
[P in keyof T]: Box<T[P]>;
|
||||
};
|
||||
declare function boxify<T>(obj: T): Boxified<T>;
|
||||
declare type A = {
|
||||
a: string;
|
||||
};
|
||||
declare type B = {
|
||||
b: string;
|
||||
};
|
||||
declare type C = {
|
||||
c: string;
|
||||
};
|
||||
declare function f1(x: A | B | C | undefined): Boxified<A> | Boxified<B> | Boxified<C> | undefined;
|
||||
declare type T00 = Partial<A | B | C>;
|
||||
declare type T01 = Readonly<A | B | C | null | undefined>;
|
||||
declare type T02 = Boxified<A | B[] | C | string>;
|
||||
declare type T03 = Readonly<string | number | boolean | null | undefined | void>;
|
||||
declare type T04 = Boxified<string | number | boolean | null | undefined | void>;
|
||||
declare type T05 = Partial<"hello" | "world" | 42>;
|
||||
declare type BoxifiedWithSentinel<T, U> = {
|
||||
[P in keyof T]: Box<T[P]> | U;
|
||||
};
|
||||
declare type T10 = BoxifiedWithSentinel<A | B | C, null>;
|
||||
declare type T11 = BoxifiedWithSentinel<A | B | C, undefined>;
|
||||
declare type T12 = BoxifiedWithSentinel<string, undefined>;
|
||||
declare type DeepReadonly<T> = {
|
||||
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
||||
};
|
||||
declare type Foo = {
|
||||
x: number;
|
||||
y: {
|
||||
a: string;
|
||||
b: number;
|
||||
};
|
||||
z: boolean;
|
||||
};
|
||||
declare type DeepReadonlyFoo = {
|
||||
readonly x: number;
|
||||
readonly y: {
|
||||
readonly a: string;
|
||||
readonly b: number;
|
||||
};
|
||||
readonly z: boolean;
|
||||
};
|
||||
declare var x1: DeepReadonly<Foo>;
|
||||
declare var x1: DeepReadonlyFoo;
|
||||
198
tests/baselines/reference/mappedTypes4.symbols
Normal file
198
tests/baselines/reference/mappedTypes4.symbols
Normal file
@@ -0,0 +1,198 @@
|
||||
=== tests/cases/conformance/types/mapped/mappedTypes4.ts ===
|
||||
|
||||
type Box<T> = {
|
||||
>Box : Symbol(Box, Decl(mappedTypes4.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 1, 9))
|
||||
|
||||
};
|
||||
|
||||
type Boxified<T> = {
|
||||
>Boxified : Symbol(Boxified, Decl(mappedTypes4.ts, 2, 2))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 4, 14))
|
||||
|
||||
[P in keyof T]: Box<T[P]>;
|
||||
>P : Symbol(P, Decl(mappedTypes4.ts, 5, 5))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 4, 14))
|
||||
>Box : Symbol(Box, Decl(mappedTypes4.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 4, 14))
|
||||
>P : Symbol(P, Decl(mappedTypes4.ts, 5, 5))
|
||||
|
||||
};
|
||||
|
||||
function boxify<T>(obj: T): Boxified<T> {
|
||||
>boxify : Symbol(boxify, Decl(mappedTypes4.ts, 6, 2))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 8, 16))
|
||||
>obj : Symbol(obj, Decl(mappedTypes4.ts, 8, 19))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 8, 16))
|
||||
>Boxified : Symbol(Boxified, Decl(mappedTypes4.ts, 2, 2))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 8, 16))
|
||||
|
||||
if (typeof obj === "object") {
|
||||
>obj : Symbol(obj, Decl(mappedTypes4.ts, 8, 19))
|
||||
|
||||
let result = {} as Boxified<T>;
|
||||
>result : Symbol(result, Decl(mappedTypes4.ts, 10, 11))
|
||||
>Boxified : Symbol(Boxified, Decl(mappedTypes4.ts, 2, 2))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 8, 16))
|
||||
|
||||
for (let k in obj) {
|
||||
>k : Symbol(k, Decl(mappedTypes4.ts, 11, 16))
|
||||
>obj : Symbol(obj, Decl(mappedTypes4.ts, 8, 19))
|
||||
|
||||
result[k] = { value: obj[k] };
|
||||
>result : Symbol(result, Decl(mappedTypes4.ts, 10, 11))
|
||||
>k : Symbol(k, Decl(mappedTypes4.ts, 11, 16))
|
||||
>value : Symbol(value, Decl(mappedTypes4.ts, 12, 25))
|
||||
>obj : Symbol(obj, Decl(mappedTypes4.ts, 8, 19))
|
||||
>k : Symbol(k, Decl(mappedTypes4.ts, 11, 16))
|
||||
}
|
||||
return result;
|
||||
>result : Symbol(result, Decl(mappedTypes4.ts, 10, 11))
|
||||
}
|
||||
return <any>obj;
|
||||
>obj : Symbol(obj, Decl(mappedTypes4.ts, 8, 19))
|
||||
}
|
||||
|
||||
type A = { a: string };
|
||||
>A : Symbol(A, Decl(mappedTypes4.ts, 17, 1))
|
||||
>a : Symbol(a, Decl(mappedTypes4.ts, 19, 10))
|
||||
|
||||
type B = { b: string };
|
||||
>B : Symbol(B, Decl(mappedTypes4.ts, 19, 23))
|
||||
>b : Symbol(b, Decl(mappedTypes4.ts, 20, 10))
|
||||
|
||||
type C = { c: string };
|
||||
>C : Symbol(C, Decl(mappedTypes4.ts, 20, 23))
|
||||
>c : Symbol(c, Decl(mappedTypes4.ts, 21, 10))
|
||||
|
||||
function f1(x: A | B | C | undefined) {
|
||||
>f1 : Symbol(f1, Decl(mappedTypes4.ts, 21, 23))
|
||||
>x : Symbol(x, Decl(mappedTypes4.ts, 23, 12))
|
||||
>A : Symbol(A, Decl(mappedTypes4.ts, 17, 1))
|
||||
>B : Symbol(B, Decl(mappedTypes4.ts, 19, 23))
|
||||
>C : Symbol(C, Decl(mappedTypes4.ts, 20, 23))
|
||||
|
||||
return boxify(x);
|
||||
>boxify : Symbol(boxify, Decl(mappedTypes4.ts, 6, 2))
|
||||
>x : Symbol(x, Decl(mappedTypes4.ts, 23, 12))
|
||||
}
|
||||
|
||||
type T00 = Partial<A | B | C>;
|
||||
>T00 : Symbol(T00, Decl(mappedTypes4.ts, 25, 1))
|
||||
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
|
||||
>A : Symbol(A, Decl(mappedTypes4.ts, 17, 1))
|
||||
>B : Symbol(B, Decl(mappedTypes4.ts, 19, 23))
|
||||
>C : Symbol(C, Decl(mappedTypes4.ts, 20, 23))
|
||||
|
||||
type T01 = Readonly<A | B | C | null | undefined>;
|
||||
>T01 : Symbol(T01, Decl(mappedTypes4.ts, 27, 30))
|
||||
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
|
||||
>A : Symbol(A, Decl(mappedTypes4.ts, 17, 1))
|
||||
>B : Symbol(B, Decl(mappedTypes4.ts, 19, 23))
|
||||
>C : Symbol(C, Decl(mappedTypes4.ts, 20, 23))
|
||||
|
||||
type T02 = Boxified<A | B[] | C | string>
|
||||
>T02 : Symbol(T02, Decl(mappedTypes4.ts, 28, 50))
|
||||
>Boxified : Symbol(Boxified, Decl(mappedTypes4.ts, 2, 2))
|
||||
>A : Symbol(A, Decl(mappedTypes4.ts, 17, 1))
|
||||
>B : Symbol(B, Decl(mappedTypes4.ts, 19, 23))
|
||||
>C : Symbol(C, Decl(mappedTypes4.ts, 20, 23))
|
||||
|
||||
type T03 = Readonly<string | number | boolean | null | undefined | void>;
|
||||
>T03 : Symbol(T03, Decl(mappedTypes4.ts, 29, 41))
|
||||
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
|
||||
|
||||
type T04 = Boxified<string | number | boolean | null | undefined | void>;
|
||||
>T04 : Symbol(T04, Decl(mappedTypes4.ts, 30, 73))
|
||||
>Boxified : Symbol(Boxified, Decl(mappedTypes4.ts, 2, 2))
|
||||
|
||||
type T05 = Partial<"hello" | "world" | 42>;
|
||||
>T05 : Symbol(T05, Decl(mappedTypes4.ts, 31, 73))
|
||||
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
|
||||
|
||||
type BoxifiedWithSentinel<T, U> = {
|
||||
>BoxifiedWithSentinel : Symbol(BoxifiedWithSentinel, Decl(mappedTypes4.ts, 32, 43))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 34, 26))
|
||||
>U : Symbol(U, Decl(mappedTypes4.ts, 34, 28))
|
||||
|
||||
[P in keyof T]: Box<T[P]> | U;
|
||||
>P : Symbol(P, Decl(mappedTypes4.ts, 35, 5))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 34, 26))
|
||||
>Box : Symbol(Box, Decl(mappedTypes4.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 34, 26))
|
||||
>P : Symbol(P, Decl(mappedTypes4.ts, 35, 5))
|
||||
>U : Symbol(U, Decl(mappedTypes4.ts, 34, 28))
|
||||
}
|
||||
|
||||
type T10 = BoxifiedWithSentinel<A | B | C, null>;
|
||||
>T10 : Symbol(T10, Decl(mappedTypes4.ts, 36, 1))
|
||||
>BoxifiedWithSentinel : Symbol(BoxifiedWithSentinel, Decl(mappedTypes4.ts, 32, 43))
|
||||
>A : Symbol(A, Decl(mappedTypes4.ts, 17, 1))
|
||||
>B : Symbol(B, Decl(mappedTypes4.ts, 19, 23))
|
||||
>C : Symbol(C, Decl(mappedTypes4.ts, 20, 23))
|
||||
|
||||
type T11 = BoxifiedWithSentinel<A | B | C, undefined>;
|
||||
>T11 : Symbol(T11, Decl(mappedTypes4.ts, 38, 49))
|
||||
>BoxifiedWithSentinel : Symbol(BoxifiedWithSentinel, Decl(mappedTypes4.ts, 32, 43))
|
||||
>A : Symbol(A, Decl(mappedTypes4.ts, 17, 1))
|
||||
>B : Symbol(B, Decl(mappedTypes4.ts, 19, 23))
|
||||
>C : Symbol(C, Decl(mappedTypes4.ts, 20, 23))
|
||||
|
||||
type T12 = BoxifiedWithSentinel<string, undefined>;
|
||||
>T12 : Symbol(T12, Decl(mappedTypes4.ts, 39, 54))
|
||||
>BoxifiedWithSentinel : Symbol(BoxifiedWithSentinel, Decl(mappedTypes4.ts, 32, 43))
|
||||
|
||||
type DeepReadonly<T> = {
|
||||
>DeepReadonly : Symbol(DeepReadonly, Decl(mappedTypes4.ts, 40, 51))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 42, 18))
|
||||
|
||||
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
||||
>P : Symbol(P, Decl(mappedTypes4.ts, 43, 14))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 42, 18))
|
||||
>DeepReadonly : Symbol(DeepReadonly, Decl(mappedTypes4.ts, 40, 51))
|
||||
>T : Symbol(T, Decl(mappedTypes4.ts, 42, 18))
|
||||
>P : Symbol(P, Decl(mappedTypes4.ts, 43, 14))
|
||||
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
>Foo : Symbol(Foo, Decl(mappedTypes4.ts, 44, 2))
|
||||
|
||||
x: number;
|
||||
>x : Symbol(x, Decl(mappedTypes4.ts, 46, 12))
|
||||
|
||||
y: { a: string, b: number };
|
||||
>y : Symbol(y, Decl(mappedTypes4.ts, 47, 14))
|
||||
>a : Symbol(a, Decl(mappedTypes4.ts, 48, 8))
|
||||
>b : Symbol(b, Decl(mappedTypes4.ts, 48, 19))
|
||||
|
||||
z: boolean;
|
||||
>z : Symbol(z, Decl(mappedTypes4.ts, 48, 32))
|
||||
|
||||
};
|
||||
|
||||
type DeepReadonlyFoo = {
|
||||
>DeepReadonlyFoo : Symbol(DeepReadonlyFoo, Decl(mappedTypes4.ts, 50, 2))
|
||||
|
||||
readonly x: number;
|
||||
>x : Symbol(x, Decl(mappedTypes4.ts, 52, 24))
|
||||
|
||||
readonly y: { readonly a: string, readonly b: number };
|
||||
>y : Symbol(y, Decl(mappedTypes4.ts, 53, 23))
|
||||
>a : Symbol(a, Decl(mappedTypes4.ts, 54, 17))
|
||||
>b : Symbol(b, Decl(mappedTypes4.ts, 54, 37))
|
||||
|
||||
readonly z: boolean;
|
||||
>z : Symbol(z, Decl(mappedTypes4.ts, 54, 59))
|
||||
|
||||
};
|
||||
|
||||
var x1: DeepReadonly<Foo>;
|
||||
>x1 : Symbol(x1, Decl(mappedTypes4.ts, 58, 3), Decl(mappedTypes4.ts, 59, 3))
|
||||
>DeepReadonly : Symbol(DeepReadonly, Decl(mappedTypes4.ts, 40, 51))
|
||||
>Foo : Symbol(Foo, Decl(mappedTypes4.ts, 44, 2))
|
||||
|
||||
var x1: DeepReadonlyFoo;
|
||||
>x1 : Symbol(x1, Decl(mappedTypes4.ts, 58, 3), Decl(mappedTypes4.ts, 59, 3))
|
||||
>DeepReadonlyFoo : Symbol(DeepReadonlyFoo, Decl(mappedTypes4.ts, 50, 2))
|
||||
|
||||
213
tests/baselines/reference/mappedTypes4.types
Normal file
213
tests/baselines/reference/mappedTypes4.types
Normal file
@@ -0,0 +1,213 @@
|
||||
=== tests/cases/conformance/types/mapped/mappedTypes4.ts ===
|
||||
|
||||
type Box<T> = {
|
||||
>Box : Box<T>
|
||||
>T : T
|
||||
|
||||
};
|
||||
|
||||
type Boxified<T> = {
|
||||
>Boxified : Boxified<T>
|
||||
>T : T
|
||||
|
||||
[P in keyof T]: Box<T[P]>;
|
||||
>P : P
|
||||
>T : T
|
||||
>Box : Box<T>
|
||||
>T : T
|
||||
>P : P
|
||||
|
||||
};
|
||||
|
||||
function boxify<T>(obj: T): Boxified<T> {
|
||||
>boxify : <T>(obj: T) => Boxified<T>
|
||||
>T : T
|
||||
>obj : T
|
||||
>T : T
|
||||
>Boxified : Boxified<T>
|
||||
>T : T
|
||||
|
||||
if (typeof obj === "object") {
|
||||
>typeof obj === "object" : boolean
|
||||
>typeof obj : string
|
||||
>obj : T
|
||||
>"object" : "object"
|
||||
|
||||
let result = {} as Boxified<T>;
|
||||
>result : Boxified<T>
|
||||
>{} as Boxified<T> : Boxified<T>
|
||||
>{} : {}
|
||||
>Boxified : Boxified<T>
|
||||
>T : T
|
||||
|
||||
for (let k in obj) {
|
||||
>k : keyof T
|
||||
>obj : T
|
||||
|
||||
result[k] = { value: obj[k] };
|
||||
>result[k] = { value: obj[k] } : { value: T[keyof T]; }
|
||||
>result[k] : Box<T[keyof T]>
|
||||
>result : Boxified<T>
|
||||
>k : keyof T
|
||||
>{ value: obj[k] } : { value: T[keyof T]; }
|
||||
>value : T[keyof T]
|
||||
>obj[k] : T[keyof T]
|
||||
>obj : T
|
||||
>k : keyof T
|
||||
}
|
||||
return result;
|
||||
>result : Boxified<T>
|
||||
}
|
||||
return <any>obj;
|
||||
><any>obj : any
|
||||
>obj : never
|
||||
}
|
||||
|
||||
type A = { a: string };
|
||||
>A : A
|
||||
>a : string
|
||||
|
||||
type B = { b: string };
|
||||
>B : B
|
||||
>b : string
|
||||
|
||||
type C = { c: string };
|
||||
>C : C
|
||||
>c : string
|
||||
|
||||
function f1(x: A | B | C | undefined) {
|
||||
>f1 : (x: A | B | C | undefined) => Boxified<A> | Boxified<B> | Boxified<C> | undefined
|
||||
>x : A | B | C | undefined
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
|
||||
return boxify(x);
|
||||
>boxify(x) : Boxified<A> | Boxified<B> | Boxified<C> | undefined
|
||||
>boxify : <T>(obj: T) => Boxified<T>
|
||||
>x : A | B | C | undefined
|
||||
}
|
||||
|
||||
type T00 = Partial<A | B | C>;
|
||||
>T00 : Partial<A> | Partial<B> | Partial<C>
|
||||
>Partial : Partial<T>
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
|
||||
type T01 = Readonly<A | B | C | null | undefined>;
|
||||
>T01 : Readonly<A> | Readonly<B> | Readonly<C> | null | undefined
|
||||
>Readonly : Readonly<T>
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
>null : null
|
||||
|
||||
type T02 = Boxified<A | B[] | C | string>
|
||||
>T02 : string | Boxified<A> | Boxified<C> | Boxified<B[]>
|
||||
>Boxified : Boxified<T>
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
|
||||
type T03 = Readonly<string | number | boolean | null | undefined | void>;
|
||||
>T03 : string | number | boolean | void | null | undefined
|
||||
>Readonly : Readonly<T>
|
||||
>null : null
|
||||
|
||||
type T04 = Boxified<string | number | boolean | null | undefined | void>;
|
||||
>T04 : string | number | boolean | void | null | undefined
|
||||
>Boxified : Boxified<T>
|
||||
>null : null
|
||||
|
||||
type T05 = Partial<"hello" | "world" | 42>;
|
||||
>T05 : "hello" | "world" | 42
|
||||
>Partial : Partial<T>
|
||||
|
||||
type BoxifiedWithSentinel<T, U> = {
|
||||
>BoxifiedWithSentinel : BoxifiedWithSentinel<T, U>
|
||||
>T : T
|
||||
>U : U
|
||||
|
||||
[P in keyof T]: Box<T[P]> | U;
|
||||
>P : P
|
||||
>T : T
|
||||
>Box : Box<T>
|
||||
>T : T
|
||||
>P : P
|
||||
>U : U
|
||||
}
|
||||
|
||||
type T10 = BoxifiedWithSentinel<A | B | C, null>;
|
||||
>T10 : BoxifiedWithSentinel<A, null> | BoxifiedWithSentinel<B, null> | BoxifiedWithSentinel<C, null>
|
||||
>BoxifiedWithSentinel : BoxifiedWithSentinel<T, U>
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
>null : null
|
||||
|
||||
type T11 = BoxifiedWithSentinel<A | B | C, undefined>;
|
||||
>T11 : BoxifiedWithSentinel<A, undefined> | BoxifiedWithSentinel<B, undefined> | BoxifiedWithSentinel<C, undefined>
|
||||
>BoxifiedWithSentinel : BoxifiedWithSentinel<T, U>
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
|
||||
type T12 = BoxifiedWithSentinel<string, undefined>;
|
||||
>T12 : string
|
||||
>BoxifiedWithSentinel : BoxifiedWithSentinel<T, U>
|
||||
|
||||
type DeepReadonly<T> = {
|
||||
>DeepReadonly : DeepReadonly<T>
|
||||
>T : T
|
||||
|
||||
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
||||
>P : P
|
||||
>T : T
|
||||
>DeepReadonly : DeepReadonly<T>
|
||||
>T : T
|
||||
>P : P
|
||||
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
>Foo : Foo
|
||||
|
||||
x: number;
|
||||
>x : number
|
||||
|
||||
y: { a: string, b: number };
|
||||
>y : { a: string; b: number; }
|
||||
>a : string
|
||||
>b : number
|
||||
|
||||
z: boolean;
|
||||
>z : boolean
|
||||
|
||||
};
|
||||
|
||||
type DeepReadonlyFoo = {
|
||||
>DeepReadonlyFoo : DeepReadonlyFoo
|
||||
|
||||
readonly x: number;
|
||||
>x : number
|
||||
|
||||
readonly y: { readonly a: string, readonly b: number };
|
||||
>y : { readonly a: string; readonly b: number; }
|
||||
>a : string
|
||||
>b : number
|
||||
|
||||
readonly z: boolean;
|
||||
>z : boolean
|
||||
|
||||
};
|
||||
|
||||
var x1: DeepReadonly<Foo>;
|
||||
>x1 : DeepReadonly<Foo>
|
||||
>DeepReadonly : DeepReadonly<T>
|
||||
>Foo : Foo
|
||||
|
||||
var x1: DeepReadonlyFoo;
|
||||
>x1 : DeepReadonly<Foo>
|
||||
>DeepReadonlyFoo : DeepReadonlyFoo
|
||||
|
||||
62
tests/cases/conformance/types/mapped/mappedTypes4.ts
Normal file
62
tests/cases/conformance/types/mapped/mappedTypes4.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
// @strictNullChecks: true
|
||||
// @declaration: true
|
||||
|
||||
type Box<T> = {
|
||||
};
|
||||
|
||||
type Boxified<T> = {
|
||||
[P in keyof T]: Box<T[P]>;
|
||||
};
|
||||
|
||||
function boxify<T>(obj: T): Boxified<T> {
|
||||
if (typeof obj === "object") {
|
||||
let result = {} as Boxified<T>;
|
||||
for (let k in obj) {
|
||||
result[k] = { value: obj[k] };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return <any>obj;
|
||||
}
|
||||
|
||||
type A = { a: string };
|
||||
type B = { b: string };
|
||||
type C = { c: string };
|
||||
|
||||
function f1(x: A | B | C | undefined) {
|
||||
return boxify(x);
|
||||
}
|
||||
|
||||
type T00 = Partial<A | B | C>;
|
||||
type T01 = Readonly<A | B | C | null | undefined>;
|
||||
type T02 = Boxified<A | B[] | C | string>
|
||||
type T03 = Readonly<string | number | boolean | null | undefined | void>;
|
||||
type T04 = Boxified<string | number | boolean | null | undefined | void>;
|
||||
type T05 = Partial<"hello" | "world" | 42>;
|
||||
|
||||
type BoxifiedWithSentinel<T, U> = {
|
||||
[P in keyof T]: Box<T[P]> | U;
|
||||
}
|
||||
|
||||
type T10 = BoxifiedWithSentinel<A | B | C, null>;
|
||||
type T11 = BoxifiedWithSentinel<A | B | C, undefined>;
|
||||
type T12 = BoxifiedWithSentinel<string, undefined>;
|
||||
|
||||
type DeepReadonly<T> = {
|
||||
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
x: number;
|
||||
y: { a: string, b: number };
|
||||
z: boolean;
|
||||
};
|
||||
|
||||
type DeepReadonlyFoo = {
|
||||
readonly x: number;
|
||||
readonly y: { readonly a: string, readonly b: number };
|
||||
readonly z: boolean;
|
||||
};
|
||||
|
||||
var x1: DeepReadonly<Foo>;
|
||||
var x1: DeepReadonlyFoo;
|
||||
Reference in New Issue
Block a user