Complete the code to declare a variable that can be a string or a number using a union type.
let value: string [1] number;The | symbol is used to create a union type, meaning the variable can be either type.
Complete the code to declare a type that combines two interfaces using an intersection.
type Person = Name [1] Age;The & symbol creates an intersection type, combining all properties from both types.
Fix the error in the function parameter type to accept either a string or number using union.
function printValue(value: string [1] number) { console.log(value); }The function parameter should use a union type with | to accept string or number.
Fill both blanks to create a type that is either a string or a number and also has a length property.
type StringOrNumberWithLength = (string [1] number) [2] { length: number };
First, use | to create a union of string or number, then use & to intersect with an object having a length property.
Fill all three blanks to create a function that accepts either a string or number and returns an object with the value and its type.
function describeValue(value: string [1] number): { val: [2], type: string } { return { val: value, type: typeof value }; }
The parameter uses union | to accept string or number. The return type's val property is also string | number.