-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26063 from Microsoft/mappedTypesArraysTuples
Improved mapped type support for arrays and tuples
- Loading branch information
Showing
6 changed files
with
773 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
//// [mappedTypesArraysTuples.ts] | ||
type Box<T> = { value: T }; | ||
type Boxified<T> = { [P in keyof T]: Box<T[P]> }; | ||
|
||
type T00 = Boxified<[number, string?, ...boolean[]]>; | ||
type T01 = Partial<[number, string?, ...boolean[]]>; | ||
type T02 = Required<[number, string?, ...boolean[]]>; | ||
|
||
type T10 = Boxified<string[]>; | ||
type T11 = Partial<string[]>; | ||
type T12 = Required<string[]>; | ||
type T13 = Boxified<ReadonlyArray<string>>; | ||
type T14 = Partial<ReadonlyArray<string>>; | ||
type T15 = Required<ReadonlyArray<string>>; | ||
|
||
type T20 = Boxified<(string | undefined)[]>; | ||
type T21 = Partial<(string | undefined)[]>; | ||
type T22 = Required<(string | undefined)[]>; | ||
type T23 = Boxified<ReadonlyArray<string | undefined>>; | ||
type T24 = Partial<ReadonlyArray<string | undefined>>; | ||
type T25 = Required<ReadonlyArray<string | undefined>>; | ||
|
||
type T30 = Boxified<Partial<string[]>>; | ||
type T31 = Partial<Boxified<string[]>>; | ||
|
||
type A = { a: string }; | ||
type B = { b: string }; | ||
|
||
type T40 = Boxified<A | A[] | ReadonlyArray<A> | [A, B] | string | string[]>; | ||
|
||
declare function unboxify<T>(x: Boxified<T>): T; | ||
|
||
declare let x10: [Box<number>, Box<string>, ...Box<boolean>[]]; | ||
let y10 = unboxify(x10); | ||
|
||
declare let x11: Box<number>[]; | ||
let y11 = unboxify(x11); | ||
|
||
declare let x12: { a: Box<number>, b: Box<string[]> }; | ||
let y12 = unboxify(x12); | ||
|
||
declare function nonpartial<T>(x: Partial<T>): T; | ||
|
||
declare let x20: [number | undefined, string?, ...boolean[]]; | ||
let y20 = nonpartial(x20); | ||
|
||
declare let x21: (number | undefined)[]; | ||
let y21 = nonpartial(x21); | ||
|
||
declare let x22: { a: number | undefined, b?: string[] }; | ||
let y22 = nonpartial(x22); | ||
|
||
type Awaited<T> = T extends PromiseLike<infer U> ? U : T; | ||
type Awaitified<T> = { [P in keyof T]: Awaited<T[P]> }; | ||
|
||
declare function all<T extends any[]>(...values: T): Promise<Awaitified<T>>; | ||
|
||
function f1(a: number, b: Promise<number>, c: string[], d: Promise<string[]>) { | ||
let x1 = all(a); | ||
let x2 = all(a, b); | ||
let x3 = all(a, b, c); | ||
let x4 = all(a, b, c, d); | ||
} | ||
|
||
|
||
//// [mappedTypesArraysTuples.js] | ||
"use strict"; | ||
var y10 = unboxify(x10); | ||
var y11 = unboxify(x11); | ||
var y12 = unboxify(x12); | ||
var y20 = nonpartial(x20); | ||
var y21 = nonpartial(x21); | ||
var y22 = nonpartial(x22); | ||
function f1(a, b, c, d) { | ||
var x1 = all(a); | ||
var x2 = all(a, b); | ||
var x3 = all(a, b, c); | ||
var x4 = all(a, b, c, d); | ||
} | ||
|
||
|
||
//// [mappedTypesArraysTuples.d.ts] | ||
declare type Box<T> = { | ||
value: T; | ||
}; | ||
declare type Boxified<T> = { | ||
[P in keyof T]: Box<T[P]>; | ||
}; | ||
declare type T00 = Boxified<[number, string?, ...boolean[]]>; | ||
declare type T01 = Partial<[number, string?, ...boolean[]]>; | ||
declare type T02 = Required<[number, string?, ...boolean[]]>; | ||
declare type T10 = Boxified<string[]>; | ||
declare type T11 = Partial<string[]>; | ||
declare type T12 = Required<string[]>; | ||
declare type T13 = Boxified<ReadonlyArray<string>>; | ||
declare type T14 = Partial<ReadonlyArray<string>>; | ||
declare type T15 = Required<ReadonlyArray<string>>; | ||
declare type T20 = Boxified<(string | undefined)[]>; | ||
declare type T21 = Partial<(string | undefined)[]>; | ||
declare type T22 = Required<(string | undefined)[]>; | ||
declare type T23 = Boxified<ReadonlyArray<string | undefined>>; | ||
declare type T24 = Partial<ReadonlyArray<string | undefined>>; | ||
declare type T25 = Required<ReadonlyArray<string | undefined>>; | ||
declare type T30 = Boxified<Partial<string[]>>; | ||
declare type T31 = Partial<Boxified<string[]>>; | ||
declare type A = { | ||
a: string; | ||
}; | ||
declare type B = { | ||
b: string; | ||
}; | ||
declare type T40 = Boxified<A | A[] | ReadonlyArray<A> | [A, B] | string | string[]>; | ||
declare function unboxify<T>(x: Boxified<T>): T; | ||
declare let x10: [Box<number>, Box<string>, ...Box<boolean>[]]; | ||
declare let y10: [number, string, ...boolean[]]; | ||
declare let x11: Box<number>[]; | ||
declare let y11: number[]; | ||
declare let x12: { | ||
a: Box<number>; | ||
b: Box<string[]>; | ||
}; | ||
declare let y12: { | ||
a: number; | ||
b: string[]; | ||
}; | ||
declare function nonpartial<T>(x: Partial<T>): T; | ||
declare let x20: [number | undefined, string?, ...boolean[]]; | ||
declare let y20: [number, string, ...boolean[]]; | ||
declare let x21: (number | undefined)[]; | ||
declare let y21: number[]; | ||
declare let x22: { | ||
a: number | undefined; | ||
b?: string[]; | ||
}; | ||
declare let y22: { | ||
a: number; | ||
b: string[]; | ||
}; | ||
declare type Awaited<T> = T extends PromiseLike<infer U> ? U : T; | ||
declare type Awaitified<T> = { | ||
[P in keyof T]: Awaited<T[P]>; | ||
}; | ||
declare function all<T extends any[]>(...values: T): Promise<Awaitified<T>>; | ||
declare function f1(a: number, b: Promise<number>, c: string[], d: Promise<string[]>): void; |
Oops, something went wrong.