PetType that is a union of the strings 'dog', 'cat', and 'bird'.myPet with the type PetType and assign it the value 'cat'.myPet.PetType that is a union of the strings 'dog', 'cat', and 'bird'.myPet with the type PetType and assign it the value 'cat'.myPet.PetType that is a union of the strings 'dog', 'cat', and 'bird'.Use the type keyword followed by the alias name, then assign the union of string literals separated by |.
myPet with the type PetType and assign it the value 'cat'.Declare myPet with let, specify the type PetType, and assign the string 'cat'.
describePet that takes a parameter pet of type PetType and returns a string describing the pet type. Then call describePet with myPet and store the result in a variable called description.Define a function with parameter pet of type PetType that returns a string using a template literal.
description using console.log.Use console.log(description) to print the description.
What does a type alias for unions in TypeScript do?
Which of the following is the correct syntax to create a type alias MyType that can be either string or number?
type to create a type alias, not alias.|, not &. So string | number is correct.What will be the output of the following TypeScript code?
type Status = "success" | "error";
function printStatus(s: Status) {
console.log(s);
}
printStatus("success");
printStatus("error");
// printStatus("pending"); // Uncommenting this line causes errorIdentify the error in this TypeScript code using a type alias for unions:
type ID = number | string; let userId: ID = true;
true is boolean, which is not allowed by the union.Given the type alias type Response = { status: "ok"; data: string } | { status: "error"; error: string };, which of the following objects matches the Response type?
Pass the test and this pattern moves unknown