See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types
Conditional types in which the checked type is a naked type parameter...
Google doesn't help, or answers are for C#, which I don't know. Couldn't find the term in Typescript docs either. Getting a meaning from context is also hard...
BTW I do know what a "type parameter" is. But what does "naked" mean?
What does ?: mean in TypeScript? Using a question mark followed by a colon ( ?: ) means a property is optional. That said, a property can either have a value based on the type defined or its value can be undefined .
This is not possible.
The never type is TypeScript's bottom type, the type for values that never occur. So why is the combination of a conditional type and the never type useful? It effectively allows us to remove constituent types from a union type.
interfacePersonReadonly{ readonlyname: string; readonlyage: number; This happens often enough in JavaScript that TypeScript provides a way to create new types based on old types — mapped types. In a mapped type, the new type transforms each property in the old type in the same way.
TypeScript with WebGL Helping with JavaScript Quick Fixes Errors Explore how TypeScript extends JavaScript to add more safety and tooling. Primitives Any Literals Union and Intersection Types Unknown and Never Type Primitives Tuples Built-in Utility Types Nullable Types Meta-Types Conditional Types Discriminate Types Indexed Types Mapped Types
A predicate takes the form parameterName is Type, where parameterNamemust be the name of a parameter from the current function signature. Any time isFishis called with some variable, TypeScript will narrowthat variable to that specific type if the original type is compatible. ts // Both calls to 'swim' and 'fly' are now okay.
When they say naked here, they mean that the type parameter is present without being wrapped in another type, (ie, an array, or a tuple, or a function, or a promise or any other generic type)
Ex:
type NakedUsage<T> = T extends boolean ? "YES" : "NO" type WrappedUsage<T> = [T] extends [boolean] ? "YES" : "NO"; // wrapped in a tuple
The reason naked vs non nakes is important is that naked usages distribute over a union, meaning the conditional type is applied for each member of the union and the result will be the union of all application
type Distributed = NakedUsage<number | boolean > // = NakedUsage<number> | NakedUsage<boolean> = "NO" | "YES" type NotDistributed = WrappedUsage<number | boolean > // "NO" type NotDistributed2 = WrappedUsage<boolean > // "YES"
Read here about conditional type distribution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With