We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
in
interface Foo { abc: number; } interface Bar { def: string; } declare let x: Foo | Bar; if ("abc" in x) { x // Foo } else { x // Bar }
if
x
Bar
never
override
#2000 #13217
.d.ts
overrride
--strict
Accepting PRs
#12424
New type operator: T extends U ? X : Y
T extends U ? X : Y
T
U
X
Y
Can make some handy types!
type Diff<T, U> = T extends U ? never : T; type TypeName<T> = T extends string ? "string" : T extends number ? "number" : T extends boolean ? "boolean" : T extends undefined ? "undefined" : T extends Function ? "function" : T extends string ? "string" : "object"; type NonNullable<T> = Diff<T, null | undefined>; type DeepReadonly<T> = T extends object ? { readonly [P in keyof T]: DeepReadonly<T[P]> } : T; // Type: "a" | "d" type T0 = Diff<"a" | "b" | "c" | "d", "b" | "c">; // Type: "string" | "function" type T1 = TypeName<string | (() => void)>; // Type: string | number type T2 = Diff<string | number | (() => void), Function>; function f1<T>(x: T, y: NonNullable<T>) { x = y; y = x; }
How do these interact with any and never?
any
Question: Should T extends U be a separate type operator from X ? Y : Z?
T extends U
X ? Y : Z
Should we have && operators as well?`
&&
If we did that, it introduces some more syntactical ambiguity.
f<T && U>(5)
f < T && U > 5
f<T && U>
What about inference for a given branch?
infer
type ReturnTypeOf<T> = from T infer R in (...args: any[]) => R: R
(...args: any[]) => R
Why did we move away from thinking about match types?
match
Does this give you the awaited type?
awaited
The text was updated successfully, but these errors were encountered:
No branches or pull requests
in
operators as a type guardif
, it"s not appropriate to say that thex
couldn't be aBar
.never
in the false branch/else branch of the conditional.The
override
keyword#2000
#13217
.d.ts
files?overrride
override
when flag is off.override
.--strict
?Accepting PRs
last year.Conditional Types
#12424
New type operator:
T extends U ? X : Y
T
does to its union constituents (orT
itself if not a union), checks if each of those types is assignable toU
.X
, otherwiseY
.T
is not known, the type remains unevaluated.T
is a union, this distributes over the union.T
seems to make the most sense.Can make some handy types!
How do these interact with
any
andnever
?any
gives both branches of the conditional.never
gives never.Question: Should
T extends U
be a separate type operator fromX ? Y : Z
?Should we have
&&
operators as well?`If we did that, it introduces some more syntactical ambiguity.
f<T && U>(5)
, while a strange way to writef < T && U > 5
, feels odd.f<T && U>
What about inference for a given branch?
infer
operator?type ReturnTypeOf<T> = from T infer R in (...args: any[]) => R: R
T
like(...args: any[]) => R
.Why did we move away from thinking about
match
types?Does this give you the
awaited
type?The text was updated successfully, but these errors were encountered: