Complete the code to remove null and undefined from the type using NonNullable.
type CleanType = NonNullable<[1]>;The NonNullable type removes null and undefined from the given type. Here, it removes them from string | null | undefined, leaving just string.
Complete the code to define a variable that cannot be null or undefined using NonNullable.
let value: NonNullable<[1]> = "hello";
The type string | null | undefined includes both null and undefined. Using NonNullable removes these, so value can only be a string.
Fix the error in the code by using NonNullable correctly.
function greet(name: [1]) {
console.log(`Hello, ${name}!`);
}
greet(null);string | null which allows null.string without considering the original type.The function parameter name should not accept null. Using NonNullable removes null, so the function only accepts strings.
Fill both blanks to create a type that excludes null and undefined from a union type.
type Cleaned = NonNullable<[1] | [2]>;
The union string | null includes null. Using NonNullable removes null, leaving just string.
Fill all three blanks to define a variable type that excludes null and undefined from a union.
let data: NonNullable<[1] | [2] | [3]>;
The union string | null | undefined includes both null and undefined. Using NonNullable removes these, so data can only be a string.