Reusable Types (Type Aliases)
Documentation
Anywhere a greeting is expected, you can provide a
string
, a function returning astring
, or aGreeter
instance.
Code
function getGreeting() { return "howdy"; } class MyGreeter extends Greeter { } greet("hello"); greet(getGreeting); greet(new MyGreeter());
Declaration
You can use a type alias to make a shorthand for a type:
type GreetingLike = string | (() => string) | Greeting; declare function greet(g: GreetingLike): void;
Please login to continue.