How do i create a type that can be a string or number in typescript?

Example:

type MyType = string | number;
const value: MyType = 'hello';  // This works
const anotherValue: MyType = 42;  // This also works
In TypeScript, you can use the union type (using the '|' symbol) to allow a variable to be of one of several types.

Beginner's Guide to TypeScript