-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29edef1
commit 39326d7
Showing
17 changed files
with
128 additions
and
54 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 |
---|---|---|
|
@@ -181,7 +181,7 @@ function f8<T>(x: T) { | |
>x : T | ||
|
||
x; // {} | ||
>x : T | ||
>x : T & {} | ||
} | ||
else { | ||
x; // {} | ||
|
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
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,77 @@ | ||
tests/cases/conformance/types/mapped/mappedTypes4.ts(11,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type '(T & null) | (T & object)'. | ||
|
||
|
||
==== tests/cases/conformance/types/mapped/mappedTypes4.ts (1 errors) ==== | ||
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) { | ||
~~~ | ||
!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type '(T & null) | (T & object)'. | ||
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; | ||
|
||
// Repro from #13232 | ||
|
||
type Z = { a: number }; | ||
type Clone<T> = { | ||
[P in keyof (T & {})]: T[P]; | ||
}; | ||
type M = Clone<Z>; // M should be { a: number } | ||
|
||
var z1: Z; | ||
var z1: Clone<Z>; | ||
|
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
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
Oops, something went wrong.