Add tests

This commit is contained in:
Anders Hejlsberg 2016-11-11 07:40:05 -08:00
parent 364142c062
commit e9b6ddc9ae
12 changed files with 1822 additions and 0 deletions

View file

@ -0,0 +1,146 @@
//// [mappedTypes1.ts]
type Item = { a: string, b: number, c: boolean };
type T00 = { [P in "x" | "y"]: number };
type T01 = { [P in "x" | "y"]: P };
type T02 = { [P in "a" | "b"]: Item[P]; }
type T03 = { [P in keyof Item]: Date };
type T10 = { [P in keyof Item]: Item[P] };
type T11 = { [P in keyof Item]?: Item[P] };
type T12 = { readonly [P in keyof Item]: Item[P] };
type T13 = { readonly [P in keyof Item]?: Item[P] };
type T20 = { [P in keyof Item]: Item[P] | null };
type T21 = { [P in keyof Item]: Array<Item[P]> };
type T30 = { [P in keyof any]: void };
type T31 = { [P in keyof string]: void };
type T32 = { [P in keyof number]: void };
type T33 = { [P in keyof boolean]: void };
type T34 = { [P in keyof undefined]: void };
type T35 = { [P in keyof null]: void };
type T36 = { [P in keyof void]: void };
type T37 = { [P in keyof symbol]: void };
type T38 = { [P in keyof never]: void };
declare function f1<T1>(): { [P in keyof T1]: void };
declare function f2<T1 extends string>(): { [P in keyof T1]: void };
declare function f3<T1 extends number>(): { [P in keyof T1]: void };
let x1 = f1();
let x2 = f2();
let x3 = f3();
//// [mappedTypes1.js]
var x1 = f1();
var x2 = f2();
var x3 = f3();
//// [mappedTypes1.d.ts]
declare type Item = {
a: string;
b: number;
c: boolean;
};
declare type T00 = {
[P in "x" | "y"]: number;
};
declare type T01 = {
[P in "x" | "y"]: P;
};
declare type T02 = {
[P in "a" | "b"]: Item[P];
};
declare type T03 = {
[P in keyof Item]: Date;
};
declare type T10 = {
[P in keyof Item]: Item[P];
};
declare type T11 = {
[P in keyof Item]?: Item[P];
};
declare type T12 = {
readonly [P in keyof Item]: Item[P];
};
declare type T13 = {
readonly [P in keyof Item]?: Item[P];
};
declare type T20 = {
[P in keyof Item]: Item[P] | null;
};
declare type T21 = {
[P in keyof Item]: Array<Item[P]>;
};
declare type T30 = {
[P in keyof any]: void;
};
declare type T31 = {
[P in keyof string]: void;
};
declare type T32 = {
[P in keyof number]: void;
};
declare type T33 = {
[P in keyof boolean]: void;
};
declare type T34 = {
[P in keyof undefined]: void;
};
declare type T35 = {
[P in keyof null]: void;
};
declare type T36 = {
[P in keyof void]: void;
};
declare type T37 = {
[P in keyof symbol]: void;
};
declare type T38 = {
[P in keyof never]: void;
};
declare function f1<T1>(): {
[P in keyof T1]: void;
};
declare function f2<T1 extends string>(): {
[P in keyof T1]: void;
};
declare function f3<T1 extends number>(): {
[P in keyof T1]: void;
};
declare let x1: {};
declare let x2: {
[x: number]: void;
toString: void;
charAt: void;
charCodeAt: void;
concat: void;
indexOf: void;
lastIndexOf: void;
localeCompare: void;
match: void;
replace: void;
search: void;
slice: void;
split: void;
substring: void;
toLowerCase: void;
toLocaleLowerCase: void;
toUpperCase: void;
toLocaleUpperCase: void;
trim: void;
length: void;
substr: void;
valueOf: void;
};
declare let x3: {
toString: void;
valueOf: void;
toFixed: void;
toExponential: void;
toPrecision: void;
toLocaleString: void;
};

View file

@ -0,0 +1,138 @@
=== tests/cases/conformance/types/mapped/mappedTypes1.ts ===
type Item = { a: string, b: number, c: boolean };
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>a : Symbol(a, Decl(mappedTypes1.ts, 1, 13))
>b : Symbol(b, Decl(mappedTypes1.ts, 1, 24))
>c : Symbol(c, Decl(mappedTypes1.ts, 1, 35))
type T00 = { [P in "x" | "y"]: number };
>T00 : Symbol(T00, Decl(mappedTypes1.ts, 1, 49))
>P : Symbol(P, Decl(mappedTypes1.ts, 3, 14))
type T01 = { [P in "x" | "y"]: P };
>T01 : Symbol(T01, Decl(mappedTypes1.ts, 3, 40))
>P : Symbol(P, Decl(mappedTypes1.ts, 4, 14))
>P : Symbol(P, Decl(mappedTypes1.ts, 4, 14))
type T02 = { [P in "a" | "b"]: Item[P]; }
>T02 : Symbol(T02, Decl(mappedTypes1.ts, 4, 35))
>P : Symbol(P, Decl(mappedTypes1.ts, 5, 14))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypes1.ts, 5, 14))
type T03 = { [P in keyof Item]: Date };
>T03 : Symbol(T03, Decl(mappedTypes1.ts, 5, 41))
>P : Symbol(P, Decl(mappedTypes1.ts, 6, 14))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>Date : Symbol(Date, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
type T10 = { [P in keyof Item]: Item[P] };
>T10 : Symbol(T10, Decl(mappedTypes1.ts, 6, 39))
>P : Symbol(P, Decl(mappedTypes1.ts, 8, 14))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypes1.ts, 8, 14))
type T11 = { [P in keyof Item]?: Item[P] };
>T11 : Symbol(T11, Decl(mappedTypes1.ts, 8, 42))
>P : Symbol(P, Decl(mappedTypes1.ts, 9, 14))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypes1.ts, 9, 14))
type T12 = { readonly [P in keyof Item]: Item[P] };
>T12 : Symbol(T12, Decl(mappedTypes1.ts, 9, 43))
>P : Symbol(P, Decl(mappedTypes1.ts, 10, 23))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypes1.ts, 10, 23))
type T13 = { readonly [P in keyof Item]?: Item[P] };
>T13 : Symbol(T13, Decl(mappedTypes1.ts, 10, 51))
>P : Symbol(P, Decl(mappedTypes1.ts, 11, 23))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypes1.ts, 11, 23))
type T20 = { [P in keyof Item]: Item[P] | null };
>T20 : Symbol(T20, Decl(mappedTypes1.ts, 11, 52))
>P : Symbol(P, Decl(mappedTypes1.ts, 13, 14))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypes1.ts, 13, 14))
type T21 = { [P in keyof Item]: Array<Item[P]> };
>T21 : Symbol(T21, Decl(mappedTypes1.ts, 13, 49))
>P : Symbol(P, Decl(mappedTypes1.ts, 14, 14))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypes1.ts, 14, 14))
type T30 = { [P in keyof any]: void };
>T30 : Symbol(T30, Decl(mappedTypes1.ts, 14, 49))
>P : Symbol(P, Decl(mappedTypes1.ts, 16, 14))
type T31 = { [P in keyof string]: void };
>T31 : Symbol(T31, Decl(mappedTypes1.ts, 16, 38))
>P : Symbol(P, Decl(mappedTypes1.ts, 17, 14))
type T32 = { [P in keyof number]: void };
>T32 : Symbol(T32, Decl(mappedTypes1.ts, 17, 41))
>P : Symbol(P, Decl(mappedTypes1.ts, 18, 14))
type T33 = { [P in keyof boolean]: void };
>T33 : Symbol(T33, Decl(mappedTypes1.ts, 18, 41))
>P : Symbol(P, Decl(mappedTypes1.ts, 19, 14))
type T34 = { [P in keyof undefined]: void };
>T34 : Symbol(T34, Decl(mappedTypes1.ts, 19, 42))
>P : Symbol(P, Decl(mappedTypes1.ts, 20, 14))
type T35 = { [P in keyof null]: void };
>T35 : Symbol(T35, Decl(mappedTypes1.ts, 20, 44))
>P : Symbol(P, Decl(mappedTypes1.ts, 21, 14))
type T36 = { [P in keyof void]: void };
>T36 : Symbol(T36, Decl(mappedTypes1.ts, 21, 39))
>P : Symbol(P, Decl(mappedTypes1.ts, 22, 14))
type T37 = { [P in keyof symbol]: void };
>T37 : Symbol(T37, Decl(mappedTypes1.ts, 22, 39))
>P : Symbol(P, Decl(mappedTypes1.ts, 23, 14))
type T38 = { [P in keyof never]: void };
>T38 : Symbol(T38, Decl(mappedTypes1.ts, 23, 41))
>P : Symbol(P, Decl(mappedTypes1.ts, 24, 14))
declare function f1<T1>(): { [P in keyof T1]: void };
>f1 : Symbol(f1, Decl(mappedTypes1.ts, 24, 40))
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 26, 20))
>P : Symbol(P, Decl(mappedTypes1.ts, 26, 30))
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 26, 20))
declare function f2<T1 extends string>(): { [P in keyof T1]: void };
>f2 : Symbol(f2, Decl(mappedTypes1.ts, 26, 53))
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 27, 20))
>P : Symbol(P, Decl(mappedTypes1.ts, 27, 45))
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 27, 20))
declare function f3<T1 extends number>(): { [P in keyof T1]: void };
>f3 : Symbol(f3, Decl(mappedTypes1.ts, 27, 68))
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 28, 20))
>P : Symbol(P, Decl(mappedTypes1.ts, 28, 45))
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 28, 20))
let x1 = f1();
>x1 : Symbol(x1, Decl(mappedTypes1.ts, 30, 3))
>f1 : Symbol(f1, Decl(mappedTypes1.ts, 24, 40))
let x2 = f2();
>x2 : Symbol(x2, Decl(mappedTypes1.ts, 31, 3))
>f2 : Symbol(f2, Decl(mappedTypes1.ts, 26, 53))
let x3 = f3();
>x3 : Symbol(x3, Decl(mappedTypes1.ts, 32, 3))
>f3 : Symbol(f3, Decl(mappedTypes1.ts, 27, 68))

View file

@ -0,0 +1,143 @@
=== tests/cases/conformance/types/mapped/mappedTypes1.ts ===
type Item = { a: string, b: number, c: boolean };
>Item : Item
>a : string
>b : number
>c : boolean
type T00 = { [P in "x" | "y"]: number };
>T00 : T00
>P : P
type T01 = { [P in "x" | "y"]: P };
>T01 : T01
>P : P
>P : P
type T02 = { [P in "a" | "b"]: Item[P]; }
>T02 : T02
>P : P
>Item : Item
>P : P
type T03 = { [P in keyof Item]: Date };
>T03 : T03
>P : P
>Item : Item
>Date : Date
type T10 = { [P in keyof Item]: Item[P] };
>T10 : T10
>P : P
>Item : Item
>Item : Item
>P : P
type T11 = { [P in keyof Item]?: Item[P] };
>T11 : T11
>P : P
>Item : Item
>Item : Item
>P : P
type T12 = { readonly [P in keyof Item]: Item[P] };
>T12 : T12
>P : P
>Item : Item
>Item : Item
>P : P
type T13 = { readonly [P in keyof Item]?: Item[P] };
>T13 : T13
>P : P
>Item : Item
>Item : Item
>P : P
type T20 = { [P in keyof Item]: Item[P] | null };
>T20 : T20
>P : P
>Item : Item
>Item : Item
>P : P
>null : null
type T21 = { [P in keyof Item]: Array<Item[P]> };
>T21 : T21
>P : P
>Item : Item
>Array : T[]
>Item : Item
>P : P
type T30 = { [P in keyof any]: void };
>T30 : T30
>P : P
type T31 = { [P in keyof string]: void };
>T31 : T31
>P : P
type T32 = { [P in keyof number]: void };
>T32 : T32
>P : P
type T33 = { [P in keyof boolean]: void };
>T33 : T33
>P : P
type T34 = { [P in keyof undefined]: void };
>T34 : T34
>P : P
type T35 = { [P in keyof null]: void };
>T35 : T35
>P : P
>null : null
type T36 = { [P in keyof void]: void };
>T36 : T36
>P : P
type T37 = { [P in keyof symbol]: void };
>T37 : T37
>P : P
type T38 = { [P in keyof never]: void };
>T38 : T38
>P : P
declare function f1<T1>(): { [P in keyof T1]: void };
>f1 : <T1>() => { [P in keyof T1]: void; }
>T1 : T1
>P : P
>T1 : T1
declare function f2<T1 extends string>(): { [P in keyof T1]: void };
>f2 : <T1 extends string>() => { [P in keyof T1]: void; }
>T1 : T1
>P : P
>T1 : T1
declare function f3<T1 extends number>(): { [P in keyof T1]: void };
>f3 : <T1 extends number>() => { [P in keyof T1]: void; }
>T1 : T1
>P : P
>T1 : T1
let x1 = f1();
>x1 : {}
>f1() : {}
>f1 : <T1>() => { [P in keyof T1]: void; }
let x2 = f2();
>x2 : { [x: number]: void; toString: void; charAt: void; charCodeAt: void; concat: void; indexOf: void; lastIndexOf: void; localeCompare: void; match: void; replace: void; search: void; slice: void; split: void; substring: void; toLowerCase: void; toLocaleLowerCase: void; toUpperCase: void; toLocaleUpperCase: void; trim: void; length: void; substr: void; valueOf: void; }
>f2() : { [x: number]: void; toString: void; charAt: void; charCodeAt: void; concat: void; indexOf: void; lastIndexOf: void; localeCompare: void; match: void; replace: void; search: void; slice: void; split: void; substring: void; toLowerCase: void; toLocaleLowerCase: void; toUpperCase: void; toLocaleUpperCase: void; trim: void; length: void; substr: void; valueOf: void; }
>f2 : <T1 extends string>() => { [P in keyof T1]: void; }
let x3 = f3();
>x3 : { toString: void; valueOf: void; toFixed: void; toExponential: void; toPrecision: void; toLocaleString: void; }
>f3() : { toString: void; valueOf: void; toFixed: void; toExponential: void; toPrecision: void; toLocaleString: void; }
>f3 : <T1 extends number>() => { [P in keyof T1]: void; }

View file

@ -0,0 +1,183 @@
//// [mappedTypes2.ts]
type Partial<T> = {
[P in keyof T]?: T[P];
};
type Readonly<T> = {
readonly [P in keyof T]: T[P];
};
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
}
type Record<K extends string | number, T> = {
[_ in K]: T;
}
type Proxy<T> = {
get(): T;
set(value: T): void;
}
type Proxify<T> = {
[P in keyof T]: Proxy<T[P]>;
}
type DeepReadonly<T> = {
readonly [P in keyof T]: DeepReadonly<T[P]>;
};
declare function assign<T>(obj: T, props: Partial<T>): void;
declare function freeze<T>(obj: T): Readonly<T>;
declare function pick<T, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>;
declare function mapObject<K extends string | number, T, U>(obj: Record<K, T>, f: (x: T) => U): Record<K, U>;
declare function proxify<T>(obj: T): Proxify<T>;
interface Shape {
name: string;
width: number;
height: number;
visible: boolean;
}
interface PartialShape {
name?: string;
width?: number;
height?: number;
visible?: boolean;
}
interface ReadonlyShape {
readonly name: string;
readonly width: number;
readonly height: number;
readonly visible: boolean;
}
function f0(s1: Shape, s2: Shape) {
assign(s1, { name: "circle" });
assign(s2, { width: 10, height: 20 });
}
function f1(shape: Shape) {
var frozen: ReadonlyShape;
var frozen: Readonly<Shape>;
var frozen = freeze(shape);
}
function f2(shape: Shape) {
var partial: PartialShape;
var partial: Partial<Shape>;
var partial: Partial<Shape> = {};
}
function f3(shape: Shape) {
const x = pick(shape, "name", "visible"); // { name: string, visible: boolean }
}
function f4() {
const rec = { foo: "hello", bar: "world", baz: "bye" };
const lengths = mapObject(rec, s => s.length); // { foo: number, bar: number, baz: number }
}
function f5(shape: Shape) {
const p = proxify(shape);
let name = p.name.get();
p.visible.set(false);
}
function f6(shape: DeepReadonly<Shape>) {
let name = shape.name; // DeepReadonly<string>
let length = name.length; // DeepReadonly<number>
let toString = length.toString; // DeepReadonly<(radix?: number) => string>
}
//// [mappedTypes2.js]
function f0(s1, s2) {
assign(s1, { name: "circle" });
assign(s2, { width: 10, height: 20 });
}
function f1(shape) {
var frozen;
var frozen;
var frozen = freeze(shape);
}
function f2(shape) {
var partial;
var partial;
var partial = {};
}
function f3(shape) {
var x = pick(shape, "name", "visible"); // { name: string, visible: boolean }
}
function f4() {
var rec = { foo: "hello", bar: "world", baz: "bye" };
var lengths = mapObject(rec, function (s) { return s.length; }); // { foo: number, bar: number, baz: number }
}
function f5(shape) {
var p = proxify(shape);
var name = p.name.get();
p.visible.set(false);
}
function f6(shape) {
var name = shape.name; // DeepReadonly<string>
var length = name.length; // DeepReadonly<number>
var toString = length.toString; // DeepReadonly<(radix?: number) => string>
}
//// [mappedTypes2.d.ts]
declare type Partial<T> = {
[P in keyof T]?: T[P];
};
declare type Readonly<T> = {
readonly [P in keyof T]: T[P];
};
declare type Pick<T, K extends keyof T> = {
[P in K]: T[P];
};
declare type Record<K extends string | number, T> = {
[_ in K]: T;
};
declare type Proxy<T> = {
get(): T;
set(value: T): void;
};
declare type Proxify<T> = {
[P in keyof T]: Proxy<T[P]>;
};
declare type DeepReadonly<T> = {
readonly [P in keyof T]: DeepReadonly<T[P]>;
};
declare function assign<T>(obj: T, props: Partial<T>): void;
declare function freeze<T>(obj: T): Readonly<T>;
declare function pick<T, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>;
declare function mapObject<K extends string | number, T, U>(obj: Record<K, T>, f: (x: T) => U): Record<K, U>;
declare function proxify<T>(obj: T): Proxify<T>;
interface Shape {
name: string;
width: number;
height: number;
visible: boolean;
}
interface PartialShape {
name?: string;
width?: number;
height?: number;
visible?: boolean;
}
interface ReadonlyShape {
readonly name: string;
readonly width: number;
readonly height: number;
readonly visible: boolean;
}
declare function f0(s1: Shape, s2: Shape): void;
declare function f1(shape: Shape): void;
declare function f2(shape: Shape): void;
declare function f3(shape: Shape): void;
declare function f4(): void;
declare function f5(shape: Shape): void;
declare function f6(shape: DeepReadonly<Shape>): void;

View file

@ -0,0 +1,331 @@
=== tests/cases/conformance/types/mapped/mappedTypes2.ts ===
type Partial<T> = {
>Partial : Symbol(Partial, Decl(mappedTypes2.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypes2.ts, 1, 13))
[P in keyof T]?: T[P];
>P : Symbol(P, Decl(mappedTypes2.ts, 2, 5))
>T : Symbol(T, Decl(mappedTypes2.ts, 1, 13))
>T : Symbol(T, Decl(mappedTypes2.ts, 1, 13))
>P : Symbol(P, Decl(mappedTypes2.ts, 2, 5))
};
type Readonly<T> = {
>Readonly : Symbol(Readonly, Decl(mappedTypes2.ts, 3, 2))
>T : Symbol(T, Decl(mappedTypes2.ts, 5, 14))
readonly [P in keyof T]: T[P];
>P : Symbol(P, Decl(mappedTypes2.ts, 6, 14))
>T : Symbol(T, Decl(mappedTypes2.ts, 5, 14))
>T : Symbol(T, Decl(mappedTypes2.ts, 5, 14))
>P : Symbol(P, Decl(mappedTypes2.ts, 6, 14))
};
type Pick<T, K extends keyof T> = {
>Pick : Symbol(Pick, Decl(mappedTypes2.ts, 7, 2))
>T : Symbol(T, Decl(mappedTypes2.ts, 9, 10))
>K : Symbol(K, Decl(mappedTypes2.ts, 9, 12))
>T : Symbol(T, Decl(mappedTypes2.ts, 9, 10))
[P in K]: T[P];
>P : Symbol(P, Decl(mappedTypes2.ts, 10, 5))
>K : Symbol(K, Decl(mappedTypes2.ts, 9, 12))
>T : Symbol(T, Decl(mappedTypes2.ts, 9, 10))
>P : Symbol(P, Decl(mappedTypes2.ts, 10, 5))
}
type Record<K extends string | number, T> = {
>Record : Symbol(Record, Decl(mappedTypes2.ts, 11, 1))
>K : Symbol(K, Decl(mappedTypes2.ts, 13, 12))
>T : Symbol(T, Decl(mappedTypes2.ts, 13, 38))
[_ in K]: T;
>_ : Symbol(_, Decl(mappedTypes2.ts, 14, 5))
>K : Symbol(K, Decl(mappedTypes2.ts, 13, 12))
>T : Symbol(T, Decl(mappedTypes2.ts, 13, 38))
}
type Proxy<T> = {
>Proxy : Symbol(Proxy, Decl(mappedTypes2.ts, 15, 1))
>T : Symbol(T, Decl(mappedTypes2.ts, 17, 11))
get(): T;
>get : Symbol(get, Decl(mappedTypes2.ts, 17, 17))
>T : Symbol(T, Decl(mappedTypes2.ts, 17, 11))
set(value: T): void;
>set : Symbol(set, Decl(mappedTypes2.ts, 18, 13))
>value : Symbol(value, Decl(mappedTypes2.ts, 19, 8))
>T : Symbol(T, Decl(mappedTypes2.ts, 17, 11))
}
type Proxify<T> = {
>Proxify : Symbol(Proxify, Decl(mappedTypes2.ts, 20, 1))
>T : Symbol(T, Decl(mappedTypes2.ts, 22, 13))
[P in keyof T]: Proxy<T[P]>;
>P : Symbol(P, Decl(mappedTypes2.ts, 23, 5))
>T : Symbol(T, Decl(mappedTypes2.ts, 22, 13))
>Proxy : Symbol(Proxy, Decl(mappedTypes2.ts, 15, 1))
>T : Symbol(T, Decl(mappedTypes2.ts, 22, 13))
>P : Symbol(P, Decl(mappedTypes2.ts, 23, 5))
}
type DeepReadonly<T> = {
>DeepReadonly : Symbol(DeepReadonly, Decl(mappedTypes2.ts, 24, 1))
>T : Symbol(T, Decl(mappedTypes2.ts, 26, 18))
readonly [P in keyof T]: DeepReadonly<T[P]>;
>P : Symbol(P, Decl(mappedTypes2.ts, 27, 14))
>T : Symbol(T, Decl(mappedTypes2.ts, 26, 18))
>DeepReadonly : Symbol(DeepReadonly, Decl(mappedTypes2.ts, 24, 1))
>T : Symbol(T, Decl(mappedTypes2.ts, 26, 18))
>P : Symbol(P, Decl(mappedTypes2.ts, 27, 14))
};
declare function assign<T>(obj: T, props: Partial<T>): void;
>assign : Symbol(assign, Decl(mappedTypes2.ts, 28, 2))
>T : Symbol(T, Decl(mappedTypes2.ts, 30, 24))
>obj : Symbol(obj, Decl(mappedTypes2.ts, 30, 27))
>T : Symbol(T, Decl(mappedTypes2.ts, 30, 24))
>props : Symbol(props, Decl(mappedTypes2.ts, 30, 34))
>Partial : Symbol(Partial, Decl(mappedTypes2.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypes2.ts, 30, 24))
declare function freeze<T>(obj: T): Readonly<T>;
>freeze : Symbol(freeze, Decl(mappedTypes2.ts, 30, 60))
>T : Symbol(T, Decl(mappedTypes2.ts, 31, 24))
>obj : Symbol(obj, Decl(mappedTypes2.ts, 31, 27))
>T : Symbol(T, Decl(mappedTypes2.ts, 31, 24))
>Readonly : Symbol(Readonly, Decl(mappedTypes2.ts, 3, 2))
>T : Symbol(T, Decl(mappedTypes2.ts, 31, 24))
declare function pick<T, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>;
>pick : Symbol(pick, Decl(mappedTypes2.ts, 31, 48))
>T : Symbol(T, Decl(mappedTypes2.ts, 32, 22))
>K : Symbol(K, Decl(mappedTypes2.ts, 32, 24))
>T : Symbol(T, Decl(mappedTypes2.ts, 32, 22))
>obj : Symbol(obj, Decl(mappedTypes2.ts, 32, 44))
>T : Symbol(T, Decl(mappedTypes2.ts, 32, 22))
>keys : Symbol(keys, Decl(mappedTypes2.ts, 32, 51))
>K : Symbol(K, Decl(mappedTypes2.ts, 32, 24))
>Pick : Symbol(Pick, Decl(mappedTypes2.ts, 7, 2))
>T : Symbol(T, Decl(mappedTypes2.ts, 32, 22))
>K : Symbol(K, Decl(mappedTypes2.ts, 32, 24))
declare function mapObject<K extends string | number, T, U>(obj: Record<K, T>, f: (x: T) => U): Record<K, U>;
>mapObject : Symbol(mapObject, Decl(mappedTypes2.ts, 32, 78))
>K : Symbol(K, Decl(mappedTypes2.ts, 33, 27))
>T : Symbol(T, Decl(mappedTypes2.ts, 33, 53))
>U : Symbol(U, Decl(mappedTypes2.ts, 33, 56))
>obj : Symbol(obj, Decl(mappedTypes2.ts, 33, 60))
>Record : Symbol(Record, Decl(mappedTypes2.ts, 11, 1))
>K : Symbol(K, Decl(mappedTypes2.ts, 33, 27))
>T : Symbol(T, Decl(mappedTypes2.ts, 33, 53))
>f : Symbol(f, Decl(mappedTypes2.ts, 33, 78))
>x : Symbol(x, Decl(mappedTypes2.ts, 33, 83))
>T : Symbol(T, Decl(mappedTypes2.ts, 33, 53))
>U : Symbol(U, Decl(mappedTypes2.ts, 33, 56))
>Record : Symbol(Record, Decl(mappedTypes2.ts, 11, 1))
>K : Symbol(K, Decl(mappedTypes2.ts, 33, 27))
>U : Symbol(U, Decl(mappedTypes2.ts, 33, 56))
declare function proxify<T>(obj: T): Proxify<T>;
>proxify : Symbol(proxify, Decl(mappedTypes2.ts, 33, 109))
>T : Symbol(T, Decl(mappedTypes2.ts, 34, 25))
>obj : Symbol(obj, Decl(mappedTypes2.ts, 34, 28))
>T : Symbol(T, Decl(mappedTypes2.ts, 34, 25))
>Proxify : Symbol(Proxify, Decl(mappedTypes2.ts, 20, 1))
>T : Symbol(T, Decl(mappedTypes2.ts, 34, 25))
interface Shape {
>Shape : Symbol(Shape, Decl(mappedTypes2.ts, 34, 48))
name: string;
>name : Symbol(Shape.name, Decl(mappedTypes2.ts, 36, 17))
width: number;
>width : Symbol(Shape.width, Decl(mappedTypes2.ts, 37, 17))
height: number;
>height : Symbol(Shape.height, Decl(mappedTypes2.ts, 38, 18))
visible: boolean;
>visible : Symbol(Shape.visible, Decl(mappedTypes2.ts, 39, 19))
}
interface PartialShape {
>PartialShape : Symbol(PartialShape, Decl(mappedTypes2.ts, 41, 1))
name?: string;
>name : Symbol(PartialShape.name, Decl(mappedTypes2.ts, 43, 24))
width?: number;
>width : Symbol(PartialShape.width, Decl(mappedTypes2.ts, 44, 18))
height?: number;
>height : Symbol(PartialShape.height, Decl(mappedTypes2.ts, 45, 19))
visible?: boolean;
>visible : Symbol(PartialShape.visible, Decl(mappedTypes2.ts, 46, 20))
}
interface ReadonlyShape {
>ReadonlyShape : Symbol(ReadonlyShape, Decl(mappedTypes2.ts, 48, 1))
readonly name: string;
>name : Symbol(ReadonlyShape.name, Decl(mappedTypes2.ts, 50, 25))
readonly width: number;
>width : Symbol(ReadonlyShape.width, Decl(mappedTypes2.ts, 51, 26))
readonly height: number;
>height : Symbol(ReadonlyShape.height, Decl(mappedTypes2.ts, 52, 27))
readonly visible: boolean;
>visible : Symbol(ReadonlyShape.visible, Decl(mappedTypes2.ts, 53, 28))
}
function f0(s1: Shape, s2: Shape) {
>f0 : Symbol(f0, Decl(mappedTypes2.ts, 55, 1))
>s1 : Symbol(s1, Decl(mappedTypes2.ts, 57, 12))
>Shape : Symbol(Shape, Decl(mappedTypes2.ts, 34, 48))
>s2 : Symbol(s2, Decl(mappedTypes2.ts, 57, 22))
>Shape : Symbol(Shape, Decl(mappedTypes2.ts, 34, 48))
assign(s1, { name: "circle" });
>assign : Symbol(assign, Decl(mappedTypes2.ts, 28, 2))
>s1 : Symbol(s1, Decl(mappedTypes2.ts, 57, 12))
>name : Symbol(name, Decl(mappedTypes2.ts, 58, 16))
assign(s2, { width: 10, height: 20 });
>assign : Symbol(assign, Decl(mappedTypes2.ts, 28, 2))
>s2 : Symbol(s2, Decl(mappedTypes2.ts, 57, 22))
>width : Symbol(width, Decl(mappedTypes2.ts, 59, 16))
>height : Symbol(height, Decl(mappedTypes2.ts, 59, 27))
}
function f1(shape: Shape) {
>f1 : Symbol(f1, Decl(mappedTypes2.ts, 60, 1))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 62, 12))
>Shape : Symbol(Shape, Decl(mappedTypes2.ts, 34, 48))
var frozen: ReadonlyShape;
>frozen : Symbol(frozen, Decl(mappedTypes2.ts, 63, 7), Decl(mappedTypes2.ts, 64, 7), Decl(mappedTypes2.ts, 65, 7))
>ReadonlyShape : Symbol(ReadonlyShape, Decl(mappedTypes2.ts, 48, 1))
var frozen: Readonly<Shape>;
>frozen : Symbol(frozen, Decl(mappedTypes2.ts, 63, 7), Decl(mappedTypes2.ts, 64, 7), Decl(mappedTypes2.ts, 65, 7))
>Readonly : Symbol(Readonly, Decl(mappedTypes2.ts, 3, 2))
>Shape : Symbol(Shape, Decl(mappedTypes2.ts, 34, 48))
var frozen = freeze(shape);
>frozen : Symbol(frozen, Decl(mappedTypes2.ts, 63, 7), Decl(mappedTypes2.ts, 64, 7), Decl(mappedTypes2.ts, 65, 7))
>freeze : Symbol(freeze, Decl(mappedTypes2.ts, 30, 60))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 62, 12))
}
function f2(shape: Shape) {
>f2 : Symbol(f2, Decl(mappedTypes2.ts, 66, 1))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 68, 12))
>Shape : Symbol(Shape, Decl(mappedTypes2.ts, 34, 48))
var partial: PartialShape;
>partial : Symbol(partial, Decl(mappedTypes2.ts, 69, 7), Decl(mappedTypes2.ts, 70, 7), Decl(mappedTypes2.ts, 71, 7))
>PartialShape : Symbol(PartialShape, Decl(mappedTypes2.ts, 41, 1))
var partial: Partial<Shape>;
>partial : Symbol(partial, Decl(mappedTypes2.ts, 69, 7), Decl(mappedTypes2.ts, 70, 7), Decl(mappedTypes2.ts, 71, 7))
>Partial : Symbol(Partial, Decl(mappedTypes2.ts, 0, 0))
>Shape : Symbol(Shape, Decl(mappedTypes2.ts, 34, 48))
var partial: Partial<Shape> = {};
>partial : Symbol(partial, Decl(mappedTypes2.ts, 69, 7), Decl(mappedTypes2.ts, 70, 7), Decl(mappedTypes2.ts, 71, 7))
>Partial : Symbol(Partial, Decl(mappedTypes2.ts, 0, 0))
>Shape : Symbol(Shape, Decl(mappedTypes2.ts, 34, 48))
}
function f3(shape: Shape) {
>f3 : Symbol(f3, Decl(mappedTypes2.ts, 72, 1))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 74, 12))
>Shape : Symbol(Shape, Decl(mappedTypes2.ts, 34, 48))
const x = pick(shape, "name", "visible"); // { name: string, visible: boolean }
>x : Symbol(x, Decl(mappedTypes2.ts, 75, 9))
>pick : Symbol(pick, Decl(mappedTypes2.ts, 31, 48))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 74, 12))
}
function f4() {
>f4 : Symbol(f4, Decl(mappedTypes2.ts, 76, 1))
const rec = { foo: "hello", bar: "world", baz: "bye" };
>rec : Symbol(rec, Decl(mappedTypes2.ts, 79, 9))
>foo : Symbol(foo, Decl(mappedTypes2.ts, 79, 17))
>bar : Symbol(bar, Decl(mappedTypes2.ts, 79, 31))
>baz : Symbol(baz, Decl(mappedTypes2.ts, 79, 45))
const lengths = mapObject(rec, s => s.length); // { foo: number, bar: number, baz: number }
>lengths : Symbol(lengths, Decl(mappedTypes2.ts, 80, 9))
>mapObject : Symbol(mapObject, Decl(mappedTypes2.ts, 32, 78))
>rec : Symbol(rec, Decl(mappedTypes2.ts, 79, 9))
>s : Symbol(s, Decl(mappedTypes2.ts, 80, 34))
>s.length : Symbol(String.length, Decl(lib.d.ts, --, --))
>s : Symbol(s, Decl(mappedTypes2.ts, 80, 34))
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
}
function f5(shape: Shape) {
>f5 : Symbol(f5, Decl(mappedTypes2.ts, 81, 1))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 83, 12))
>Shape : Symbol(Shape, Decl(mappedTypes2.ts, 34, 48))
const p = proxify(shape);
>p : Symbol(p, Decl(mappedTypes2.ts, 84, 9))
>proxify : Symbol(proxify, Decl(mappedTypes2.ts, 33, 109))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 83, 12))
let name = p.name.get();
>name : Symbol(name, Decl(mappedTypes2.ts, 85, 7))
>p.name.get : Symbol(get, Decl(mappedTypes2.ts, 17, 17))
>p.name : Symbol(name)
>p : Symbol(p, Decl(mappedTypes2.ts, 84, 9))
>name : Symbol(name)
>get : Symbol(get, Decl(mappedTypes2.ts, 17, 17))
p.visible.set(false);
>p.visible.set : Symbol(set, Decl(mappedTypes2.ts, 18, 13))
>p.visible : Symbol(visible)
>p : Symbol(p, Decl(mappedTypes2.ts, 84, 9))
>visible : Symbol(visible)
>set : Symbol(set, Decl(mappedTypes2.ts, 18, 13))
}
function f6(shape: DeepReadonly<Shape>) {
>f6 : Symbol(f6, Decl(mappedTypes2.ts, 87, 1))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 89, 12))
>DeepReadonly : Symbol(DeepReadonly, Decl(mappedTypes2.ts, 24, 1))
>Shape : Symbol(Shape, Decl(mappedTypes2.ts, 34, 48))
let name = shape.name; // DeepReadonly<string>
>name : Symbol(name, Decl(mappedTypes2.ts, 90, 7))
>shape.name : Symbol(name)
>shape : Symbol(shape, Decl(mappedTypes2.ts, 89, 12))
>name : Symbol(name)
let length = name.length; // DeepReadonly<number>
>length : Symbol(length, Decl(mappedTypes2.ts, 91, 7))
>name.length : Symbol(length)
>name : Symbol(name, Decl(mappedTypes2.ts, 90, 7))
>length : Symbol(length)
let toString = length.toString; // DeepReadonly<(radix?: number) => string>
>toString : Symbol(toString, Decl(mappedTypes2.ts, 92, 7))
>length.toString : Symbol(toString)
>length : Symbol(length, Decl(mappedTypes2.ts, 91, 7))
>toString : Symbol(toString)
}

View file

@ -0,0 +1,353 @@
=== tests/cases/conformance/types/mapped/mappedTypes2.ts ===
type Partial<T> = {
>Partial : Partial<T>
>T : T
[P in keyof T]?: T[P];
>P : P
>T : T
>T : T
>P : P
};
type Readonly<T> = {
>Readonly : Readonly<T>
>T : T
readonly [P in keyof T]: T[P];
>P : P
>T : T
>T : T
>P : P
};
type Pick<T, K extends keyof T> = {
>Pick : Pick<T, K>
>T : T
>K : K
>T : T
[P in K]: T[P];
>P : P
>K : K
>T : T
>P : P
}
type Record<K extends string | number, T> = {
>Record : Record<K, T>
>K : K
>T : T
[_ in K]: T;
>_ : _
>K : K
>T : T
}
type Proxy<T> = {
>Proxy : Proxy<T>
>T : T
get(): T;
>get : () => T
>T : T
set(value: T): void;
>set : (value: T) => void
>value : T
>T : T
}
type Proxify<T> = {
>Proxify : Proxify<T>
>T : T
[P in keyof T]: Proxy<T[P]>;
>P : P
>T : T
>Proxy : Proxy<T>
>T : T
>P : P
}
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
};
declare function assign<T>(obj: T, props: Partial<T>): void;
>assign : <T>(obj: T, props: Partial<T>) => void
>T : T
>obj : T
>T : T
>props : Partial<T>
>Partial : Partial<T>
>T : T
declare function freeze<T>(obj: T): Readonly<T>;
>freeze : <T>(obj: T) => Readonly<T>
>T : T
>obj : T
>T : T
>Readonly : Readonly<T>
>T : T
declare function pick<T, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>;
>pick : <T, K extends keyof T>(obj: T, ...keys: K[]) => Pick<T, K>
>T : T
>K : K
>T : T
>obj : T
>T : T
>keys : K[]
>K : K
>Pick : Pick<T, K>
>T : T
>K : K
declare function mapObject<K extends string | number, T, U>(obj: Record<K, T>, f: (x: T) => U): Record<K, U>;
>mapObject : <K extends string | number, T, U>(obj: Record<K, T>, f: (x: T) => U) => Record<K, U>
>K : K
>T : T
>U : U
>obj : Record<K, T>
>Record : Record<K, T>
>K : K
>T : T
>f : (x: T) => U
>x : T
>T : T
>U : U
>Record : Record<K, T>
>K : K
>U : U
declare function proxify<T>(obj: T): Proxify<T>;
>proxify : <T>(obj: T) => Proxify<T>
>T : T
>obj : T
>T : T
>Proxify : Proxify<T>
>T : T
interface Shape {
>Shape : Shape
name: string;
>name : string
width: number;
>width : number
height: number;
>height : number
visible: boolean;
>visible : boolean
}
interface PartialShape {
>PartialShape : PartialShape
name?: string;
>name : string | undefined
width?: number;
>width : number | undefined
height?: number;
>height : number | undefined
visible?: boolean;
>visible : boolean | undefined
}
interface ReadonlyShape {
>ReadonlyShape : ReadonlyShape
readonly name: string;
>name : string
readonly width: number;
>width : number
readonly height: number;
>height : number
readonly visible: boolean;
>visible : boolean
}
function f0(s1: Shape, s2: Shape) {
>f0 : (s1: Shape, s2: Shape) => void
>s1 : Shape
>Shape : Shape
>s2 : Shape
>Shape : Shape
assign(s1, { name: "circle" });
>assign(s1, { name: "circle" }) : void
>assign : <T>(obj: T, props: Partial<T>) => void
>s1 : Shape
>{ name: "circle" } : { name: string; }
>name : string
>"circle" : "circle"
assign(s2, { width: 10, height: 20 });
>assign(s2, { width: 10, height: 20 }) : void
>assign : <T>(obj: T, props: Partial<T>) => void
>s2 : Shape
>{ width: 10, height: 20 } : { width: number; height: number; }
>width : number
>10 : 10
>height : number
>20 : 20
}
function f1(shape: Shape) {
>f1 : (shape: Shape) => void
>shape : Shape
>Shape : Shape
var frozen: ReadonlyShape;
>frozen : ReadonlyShape
>ReadonlyShape : ReadonlyShape
var frozen: Readonly<Shape>;
>frozen : ReadonlyShape
>Readonly : Readonly<T>
>Shape : Shape
var frozen = freeze(shape);
>frozen : ReadonlyShape
>freeze(shape) : Readonly<Shape>
>freeze : <T>(obj: T) => Readonly<T>
>shape : Shape
}
function f2(shape: Shape) {
>f2 : (shape: Shape) => void
>shape : Shape
>Shape : Shape
var partial: PartialShape;
>partial : PartialShape
>PartialShape : PartialShape
var partial: Partial<Shape>;
>partial : PartialShape
>Partial : Partial<T>
>Shape : Shape
var partial: Partial<Shape> = {};
>partial : PartialShape
>Partial : Partial<T>
>Shape : Shape
>{} : {}
}
function f3(shape: Shape) {
>f3 : (shape: Shape) => void
>shape : Shape
>Shape : Shape
const x = pick(shape, "name", "visible"); // { name: string, visible: boolean }
>x : Pick<Shape, "name" | "visible">
>pick(shape, "name", "visible") : Pick<Shape, "name" | "visible">
>pick : <T, K extends keyof T>(obj: T, ...keys: K[]) => Pick<T, K>
>shape : Shape
>"name" : "name"
>"visible" : "visible"
}
function f4() {
>f4 : () => void
const rec = { foo: "hello", bar: "world", baz: "bye" };
>rec : { foo: string; bar: string; baz: string; }
>{ foo: "hello", bar: "world", baz: "bye" } : { foo: string; bar: string; baz: string; }
>foo : string
>"hello" : "hello"
>bar : string
>"world" : "world"
>baz : string
>"bye" : "bye"
const lengths = mapObject(rec, s => s.length); // { foo: number, bar: number, baz: number }
>lengths : Record<"foo" | "bar" | "baz", number>
>mapObject(rec, s => s.length) : Record<"foo" | "bar" | "baz", number>
>mapObject : <K extends string | number, T, U>(obj: Record<K, T>, f: (x: T) => U) => Record<K, U>
>rec : { foo: string; bar: string; baz: string; }
>s => s.length : (s: string) => number
>s : string
>s.length : number
>s : string
>length : number
}
function f5(shape: Shape) {
>f5 : (shape: Shape) => void
>shape : Shape
>Shape : Shape
const p = proxify(shape);
>p : Proxify<Shape>
>proxify(shape) : Proxify<Shape>
>proxify : <T>(obj: T) => Proxify<T>
>shape : Shape
let name = p.name.get();
>name : string
>p.name.get() : string
>p.name.get : () => string
>p.name : Proxy<string>
>p : Proxify<Shape>
>name : Proxy<string>
>get : () => string
p.visible.set(false);
>p.visible.set(false) : void
>p.visible.set : (value: boolean) => void
>p.visible : Proxy<boolean>
>p : Proxify<Shape>
>visible : Proxy<boolean>
>set : (value: boolean) => void
>false : false
}
function f6(shape: DeepReadonly<Shape>) {
>f6 : (shape: DeepReadonly<Shape>) => void
>shape : DeepReadonly<Shape>
>DeepReadonly : DeepReadonly<T>
>Shape : Shape
let name = shape.name; // DeepReadonly<string>
>name : DeepReadonly<string>
>shape.name : DeepReadonly<string>
>shape : DeepReadonly<Shape>
>name : DeepReadonly<string>
let length = name.length; // DeepReadonly<number>
>length : DeepReadonly<number>
>name.length : DeepReadonly<number>
>name : DeepReadonly<string>
>length : DeepReadonly<number>
let toString = length.toString; // DeepReadonly<(radix?: number) => string>
>toString : DeepReadonly<(radix?: number | undefined) => string>
>length.toString : DeepReadonly<(radix?: number | undefined) => string>
>length : DeepReadonly<number>
>toString : DeepReadonly<(radix?: number | undefined) => string>
}

View file

@ -0,0 +1,84 @@
//// [mappedTypes3.ts]
class Box<P> {
value: P;
}
type Boxified<T> = {
[K in keyof T]: Box<T[K]>;
}
declare function boxify<T>(obj: T): Boxified<T>;
declare function unboxify<T>(obj: Boxified<T>): T;
interface Bacon {
isPerfect: boolean;
weight: number;
}
interface BoxifiedBacon {
isPerfect: Box<boolean>;
weight: Box<number>;
}
function f1(b: Bacon) {
let bb = boxify(b);
let isPerfect = bb.isPerfect.value;
let weight = bb.weight.value;
}
function f2(bb: Boxified<Bacon>) {
let b = unboxify(bb); // Infer Bacon for T
let bool = b.isPerfect;
let weight = b.weight;
}
function f3(bb: BoxifiedBacon) {
let b = unboxify<Bacon>(bb); // Explicit type parameter required
let bool = b.isPerfect;
let weight = bb.weight;
}
//// [mappedTypes3.js]
var Box = (function () {
function Box() {
}
return Box;
}());
function f1(b) {
var bb = boxify(b);
var isPerfect = bb.isPerfect.value;
var weight = bb.weight.value;
}
function f2(bb) {
var b = unboxify(bb); // Infer Bacon for T
var bool = b.isPerfect;
var weight = b.weight;
}
function f3(bb) {
var b = unboxify(bb); // Explicit type parameter required
var bool = b.isPerfect;
var weight = bb.weight;
}
//// [mappedTypes3.d.ts]
declare class Box<P> {
value: P;
}
declare type Boxified<T> = {
[K in keyof T]: Box<T[K]>;
};
declare function boxify<T>(obj: T): Boxified<T>;
declare function unboxify<T>(obj: Boxified<T>): T;
interface Bacon {
isPerfect: boolean;
weight: number;
}
interface BoxifiedBacon {
isPerfect: Box<boolean>;
weight: Box<number>;
}
declare function f1(b: Bacon): void;
declare function f2(bb: Boxified<Bacon>): void;
declare function f3(bb: BoxifiedBacon): void;

View file

@ -0,0 +1,135 @@
=== tests/cases/conformance/types/mapped/mappedTypes3.ts ===
class Box<P> {
>Box : Symbol(Box, Decl(mappedTypes3.ts, 0, 0))
>P : Symbol(P, Decl(mappedTypes3.ts, 1, 10))
value: P;
>value : Symbol(Box.value, Decl(mappedTypes3.ts, 1, 14))
>P : Symbol(P, Decl(mappedTypes3.ts, 1, 10))
}
type Boxified<T> = {
>Boxified : Symbol(Boxified, Decl(mappedTypes3.ts, 3, 1))
>T : Symbol(T, Decl(mappedTypes3.ts, 5, 14))
[K in keyof T]: Box<T[K]>;
>K : Symbol(K, Decl(mappedTypes3.ts, 6, 5))
>T : Symbol(T, Decl(mappedTypes3.ts, 5, 14))
>Box : Symbol(Box, Decl(mappedTypes3.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypes3.ts, 5, 14))
>K : Symbol(K, Decl(mappedTypes3.ts, 6, 5))
}
declare function boxify<T>(obj: T): Boxified<T>;
>boxify : Symbol(boxify, Decl(mappedTypes3.ts, 7, 1))
>T : Symbol(T, Decl(mappedTypes3.ts, 9, 24))
>obj : Symbol(obj, Decl(mappedTypes3.ts, 9, 27))
>T : Symbol(T, Decl(mappedTypes3.ts, 9, 24))
>Boxified : Symbol(Boxified, Decl(mappedTypes3.ts, 3, 1))
>T : Symbol(T, Decl(mappedTypes3.ts, 9, 24))
declare function unboxify<T>(obj: Boxified<T>): T;
>unboxify : Symbol(unboxify, Decl(mappedTypes3.ts, 9, 48))
>T : Symbol(T, Decl(mappedTypes3.ts, 10, 26))
>obj : Symbol(obj, Decl(mappedTypes3.ts, 10, 29))
>Boxified : Symbol(Boxified, Decl(mappedTypes3.ts, 3, 1))
>T : Symbol(T, Decl(mappedTypes3.ts, 10, 26))
>T : Symbol(T, Decl(mappedTypes3.ts, 10, 26))
interface Bacon {
>Bacon : Symbol(Bacon, Decl(mappedTypes3.ts, 10, 50))
isPerfect: boolean;
>isPerfect : Symbol(Bacon.isPerfect, Decl(mappedTypes3.ts, 12, 17))
weight: number;
>weight : Symbol(Bacon.weight, Decl(mappedTypes3.ts, 13, 23))
}
interface BoxifiedBacon {
>BoxifiedBacon : Symbol(BoxifiedBacon, Decl(mappedTypes3.ts, 15, 1))
isPerfect: Box<boolean>;
>isPerfect : Symbol(BoxifiedBacon.isPerfect, Decl(mappedTypes3.ts, 17, 25))
>Box : Symbol(Box, Decl(mappedTypes3.ts, 0, 0))
weight: Box<number>;
>weight : Symbol(BoxifiedBacon.weight, Decl(mappedTypes3.ts, 18, 28))
>Box : Symbol(Box, Decl(mappedTypes3.ts, 0, 0))
}
function f1(b: Bacon) {
>f1 : Symbol(f1, Decl(mappedTypes3.ts, 20, 1))
>b : Symbol(b, Decl(mappedTypes3.ts, 22, 12))
>Bacon : Symbol(Bacon, Decl(mappedTypes3.ts, 10, 50))
let bb = boxify(b);
>bb : Symbol(bb, Decl(mappedTypes3.ts, 23, 7))
>boxify : Symbol(boxify, Decl(mappedTypes3.ts, 7, 1))
>b : Symbol(b, Decl(mappedTypes3.ts, 22, 12))
let isPerfect = bb.isPerfect.value;
>isPerfect : Symbol(isPerfect, Decl(mappedTypes3.ts, 24, 7))
>bb.isPerfect.value : Symbol(Box.value, Decl(mappedTypes3.ts, 1, 14))
>bb.isPerfect : Symbol(isPerfect)
>bb : Symbol(bb, Decl(mappedTypes3.ts, 23, 7))
>isPerfect : Symbol(isPerfect)
>value : Symbol(Box.value, Decl(mappedTypes3.ts, 1, 14))
let weight = bb.weight.value;
>weight : Symbol(weight, Decl(mappedTypes3.ts, 25, 7))
>bb.weight.value : Symbol(Box.value, Decl(mappedTypes3.ts, 1, 14))
>bb.weight : Symbol(weight)
>bb : Symbol(bb, Decl(mappedTypes3.ts, 23, 7))
>weight : Symbol(weight)
>value : Symbol(Box.value, Decl(mappedTypes3.ts, 1, 14))
}
function f2(bb: Boxified<Bacon>) {
>f2 : Symbol(f2, Decl(mappedTypes3.ts, 26, 1))
>bb : Symbol(bb, Decl(mappedTypes3.ts, 28, 12))
>Boxified : Symbol(Boxified, Decl(mappedTypes3.ts, 3, 1))
>Bacon : Symbol(Bacon, Decl(mappedTypes3.ts, 10, 50))
let b = unboxify(bb); // Infer Bacon for T
>b : Symbol(b, Decl(mappedTypes3.ts, 29, 7))
>unboxify : Symbol(unboxify, Decl(mappedTypes3.ts, 9, 48))
>bb : Symbol(bb, Decl(mappedTypes3.ts, 28, 12))
let bool = b.isPerfect;
>bool : Symbol(bool, Decl(mappedTypes3.ts, 30, 7))
>b.isPerfect : Symbol(Bacon.isPerfect, Decl(mappedTypes3.ts, 12, 17))
>b : Symbol(b, Decl(mappedTypes3.ts, 29, 7))
>isPerfect : Symbol(Bacon.isPerfect, Decl(mappedTypes3.ts, 12, 17))
let weight = b.weight;
>weight : Symbol(weight, Decl(mappedTypes3.ts, 31, 7))
>b.weight : Symbol(Bacon.weight, Decl(mappedTypes3.ts, 13, 23))
>b : Symbol(b, Decl(mappedTypes3.ts, 29, 7))
>weight : Symbol(Bacon.weight, Decl(mappedTypes3.ts, 13, 23))
}
function f3(bb: BoxifiedBacon) {
>f3 : Symbol(f3, Decl(mappedTypes3.ts, 32, 1))
>bb : Symbol(bb, Decl(mappedTypes3.ts, 34, 12))
>BoxifiedBacon : Symbol(BoxifiedBacon, Decl(mappedTypes3.ts, 15, 1))
let b = unboxify<Bacon>(bb); // Explicit type parameter required
>b : Symbol(b, Decl(mappedTypes3.ts, 35, 7))
>unboxify : Symbol(unboxify, Decl(mappedTypes3.ts, 9, 48))
>Bacon : Symbol(Bacon, Decl(mappedTypes3.ts, 10, 50))
>bb : Symbol(bb, Decl(mappedTypes3.ts, 34, 12))
let bool = b.isPerfect;
>bool : Symbol(bool, Decl(mappedTypes3.ts, 36, 7))
>b.isPerfect : Symbol(Bacon.isPerfect, Decl(mappedTypes3.ts, 12, 17))
>b : Symbol(b, Decl(mappedTypes3.ts, 35, 7))
>isPerfect : Symbol(Bacon.isPerfect, Decl(mappedTypes3.ts, 12, 17))
let weight = bb.weight;
>weight : Symbol(weight, Decl(mappedTypes3.ts, 37, 7))
>bb.weight : Symbol(BoxifiedBacon.weight, Decl(mappedTypes3.ts, 18, 28))
>bb : Symbol(bb, Decl(mappedTypes3.ts, 34, 12))
>weight : Symbol(BoxifiedBacon.weight, Decl(mappedTypes3.ts, 18, 28))
}

View file

@ -0,0 +1,138 @@
=== tests/cases/conformance/types/mapped/mappedTypes3.ts ===
class Box<P> {
>Box : Box<P>
>P : P
value: P;
>value : P
>P : P
}
type Boxified<T> = {
>Boxified : Boxified<T>
>T : T
[K in keyof T]: Box<T[K]>;
>K : K
>T : T
>Box : Box<P>
>T : T
>K : K
}
declare function boxify<T>(obj: T): Boxified<T>;
>boxify : <T>(obj: T) => Boxified<T>
>T : T
>obj : T
>T : T
>Boxified : Boxified<T>
>T : T
declare function unboxify<T>(obj: Boxified<T>): T;
>unboxify : <T>(obj: Boxified<T>) => T
>T : T
>obj : Boxified<T>
>Boxified : Boxified<T>
>T : T
>T : T
interface Bacon {
>Bacon : Bacon
isPerfect: boolean;
>isPerfect : boolean
weight: number;
>weight : number
}
interface BoxifiedBacon {
>BoxifiedBacon : BoxifiedBacon
isPerfect: Box<boolean>;
>isPerfect : Box<boolean>
>Box : Box<P>
weight: Box<number>;
>weight : Box<number>
>Box : Box<P>
}
function f1(b: Bacon) {
>f1 : (b: Bacon) => void
>b : Bacon
>Bacon : Bacon
let bb = boxify(b);
>bb : Boxified<Bacon>
>boxify(b) : Boxified<Bacon>
>boxify : <T>(obj: T) => Boxified<T>
>b : Bacon
let isPerfect = bb.isPerfect.value;
>isPerfect : boolean
>bb.isPerfect.value : boolean
>bb.isPerfect : Box<boolean>
>bb : Boxified<Bacon>
>isPerfect : Box<boolean>
>value : boolean
let weight = bb.weight.value;
>weight : number
>bb.weight.value : number
>bb.weight : Box<number>
>bb : Boxified<Bacon>
>weight : Box<number>
>value : number
}
function f2(bb: Boxified<Bacon>) {
>f2 : (bb: Boxified<Bacon>) => void
>bb : Boxified<Bacon>
>Boxified : Boxified<T>
>Bacon : Bacon
let b = unboxify(bb); // Infer Bacon for T
>b : Bacon
>unboxify(bb) : Bacon
>unboxify : <T>(obj: Boxified<T>) => T
>bb : Boxified<Bacon>
let bool = b.isPerfect;
>bool : boolean
>b.isPerfect : boolean
>b : Bacon
>isPerfect : boolean
let weight = b.weight;
>weight : number
>b.weight : number
>b : Bacon
>weight : number
}
function f3(bb: BoxifiedBacon) {
>f3 : (bb: BoxifiedBacon) => void
>bb : BoxifiedBacon
>BoxifiedBacon : BoxifiedBacon
let b = unboxify<Bacon>(bb); // Explicit type parameter required
>b : Bacon
>unboxify<Bacon>(bb) : Bacon
>unboxify : <T>(obj: Boxified<T>) => T
>Bacon : Bacon
>bb : BoxifiedBacon
let bool = b.isPerfect;
>bool : boolean
>b.isPerfect : boolean
>b : Bacon
>isPerfect : boolean
let weight = bb.weight;
>weight : Box<number>
>bb.weight : Box<number>
>bb : BoxifiedBacon
>weight : Box<number>
}

View file

@ -0,0 +1,35 @@
// @strictNullChecks: true
// @declaration: true
type Item = { a: string, b: number, c: boolean };
type T00 = { [P in "x" | "y"]: number };
type T01 = { [P in "x" | "y"]: P };
type T02 = { [P in "a" | "b"]: Item[P]; }
type T03 = { [P in keyof Item]: Date };
type T10 = { [P in keyof Item]: Item[P] };
type T11 = { [P in keyof Item]?: Item[P] };
type T12 = { readonly [P in keyof Item]: Item[P] };
type T13 = { readonly [P in keyof Item]?: Item[P] };
type T20 = { [P in keyof Item]: Item[P] | null };
type T21 = { [P in keyof Item]: Array<Item[P]> };
type T30 = { [P in keyof any]: void };
type T31 = { [P in keyof string]: void };
type T32 = { [P in keyof number]: void };
type T33 = { [P in keyof boolean]: void };
type T34 = { [P in keyof undefined]: void };
type T35 = { [P in keyof null]: void };
type T36 = { [P in keyof void]: void };
type T37 = { [P in keyof symbol]: void };
type T38 = { [P in keyof never]: void };
declare function f1<T1>(): { [P in keyof T1]: void };
declare function f2<T1 extends string>(): { [P in keyof T1]: void };
declare function f3<T1 extends number>(): { [P in keyof T1]: void };
let x1 = f1();
let x2 = f2();
let x3 = f3();

View file

@ -0,0 +1,96 @@
// @strictNullChecks: true
// @declaration: true
type Partial<T> = {
[P in keyof T]?: T[P];
};
type Readonly<T> = {
readonly [P in keyof T]: T[P];
};
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
}
type Record<K extends string | number, T> = {
[_ in K]: T;
}
type Proxy<T> = {
get(): T;
set(value: T): void;
}
type Proxify<T> = {
[P in keyof T]: Proxy<T[P]>;
}
type DeepReadonly<T> = {
readonly [P in keyof T]: DeepReadonly<T[P]>;
};
declare function assign<T>(obj: T, props: Partial<T>): void;
declare function freeze<T>(obj: T): Readonly<T>;
declare function pick<T, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>;
declare function mapObject<K extends string | number, T, U>(obj: Record<K, T>, f: (x: T) => U): Record<K, U>;
declare function proxify<T>(obj: T): Proxify<T>;
interface Shape {
name: string;
width: number;
height: number;
visible: boolean;
}
interface PartialShape {
name?: string;
width?: number;
height?: number;
visible?: boolean;
}
interface ReadonlyShape {
readonly name: string;
readonly width: number;
readonly height: number;
readonly visible: boolean;
}
function f0(s1: Shape, s2: Shape) {
assign(s1, { name: "circle" });
assign(s2, { width: 10, height: 20 });
}
function f1(shape: Shape) {
var frozen: ReadonlyShape;
var frozen: Readonly<Shape>;
var frozen = freeze(shape);
}
function f2(shape: Shape) {
var partial: PartialShape;
var partial: Partial<Shape>;
var partial: Partial<Shape> = {};
}
function f3(shape: Shape) {
const x = pick(shape, "name", "visible"); // { name: string, visible: boolean }
}
function f4() {
const rec = { foo: "hello", bar: "world", baz: "bye" };
const lengths = mapObject(rec, s => s.length); // { foo: number, bar: number, baz: number }
}
function f5(shape: Shape) {
const p = proxify(shape);
let name = p.name.get();
p.visible.set(false);
}
function f6(shape: DeepReadonly<Shape>) {
let name = shape.name; // DeepReadonly<string>
let length = name.length; // DeepReadonly<number>
let toString = length.toString; // DeepReadonly<(radix?: number) => string>
}

View file

@ -0,0 +1,40 @@
// @declaration: true
class Box<P> {
value: P;
}
type Boxified<T> = {
[K in keyof T]: Box<T[K]>;
}
declare function boxify<T>(obj: T): Boxified<T>;
declare function unboxify<T>(obj: Boxified<T>): T;
interface Bacon {
isPerfect: boolean;
weight: number;
}
interface BoxifiedBacon {
isPerfect: Box<boolean>;
weight: Box<number>;
}
function f1(b: Bacon) {
let bb = boxify(b);
let isPerfect = bb.isPerfect.value;
let weight = bb.weight.value;
}
function f2(bb: Boxified<Bacon>) {
let b = unboxify(bb); // Infer Bacon for T
let bool = b.isPerfect;
let weight = b.weight;
}
function f3(bb: BoxifiedBacon) {
let b = unboxify<Bacon>(bb); // Explicit type parameter required
let bool = b.isPerfect;
let weight = bb.weight;
}