January 2019
Beginner
210 pages
4h 47m
English
We can use a specialized signature to create multiple methods with the same name and number of parameters, but a different return type. To create a specialized signature, we must indicate the type of function parameter using a string. The string literal is used to identify which of the function overloads is invoked:
interface Document { createElement(tagName: "div"): HTMLDivElement; // specialized createElement(tagName: "span"): HTMLSpanElement; // specialized createElement(tagName: "canvas"): HTMLCanvasElement; // specialized createElement(tagName: string): HTMLElement; // non-specialized}
In the preceding example, we have declared three specialized overloaded signatures and one non-specialized signature ...
Read now
Unlock full access