microsoft / TypeScript-Handbook

Deprecated, please use the TypeScript-Website repo instead
https://github.com/microsoft/TypeScript-Website
Apache License 2.0
4.88k stars 1.13k forks source link

Declaration example does not match documentation requirements #1291

Closed ydz-one closed 4 years ago

ydz-one commented 4 years ago

https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html#reusable-types-type-aliases

Documentation:

Anywhere a greeting is expected, you can provide a string, a function returning a string, or a Greeter instance.

Code:

function getGreeting() {
    return "howdy";
}
class MyGreeter extends Greeter { }

greet("hello");
greet(getGreeting);
greet(new MyGreeter());

Declaration:

type GreetingLike = string | (() => string) | MyGreeter;

declare function greet(g: GreetingLike): void;

In order to match the documentation requirements, the first line of that declaration should be revised to: type GreetingLike = string | (() => string) | Greeter;

ydz-one commented 4 years ago

Created PR to fix issue