- Hands-On Functional Programming with TypeScript
- Remo H. Jansen
- 167字
- 2021-07-02 14:03:14
Specialized overloading signature
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 for the function named createElement.
When we declare a specialized signature in an object, it must be assignable to at least one non-specialized signature in the same object. This can be observed in the preceding example, as the createElement property belongs to a type that contains three specialized signatures, all of which are assignable to the non-specialized signature in the type.
When writing overloaded declarations, we must list the non-specialized signature last.
- Java范例大全
- 單片機(jī)C語(yǔ)言程序設(shè)計(jì)實(shí)訓(xùn)100例:基于STC8051+Proteus仿真與實(shí)戰(zhàn)
- OpenCV 3和Qt5計(jì)算機(jī)視覺應(yīng)用開發(fā)
- Practical Game Design
- Mastering Python Networking
- 小學(xué)生C++創(chuàng)意編程(視頻教學(xué)版)
- MySQL從入門到精通(軟件開發(fā)視頻大講堂)
- Test-Driven Development with Django
- C語(yǔ)言程序設(shè)計(jì)實(shí)訓(xùn)教程與水平考試指導(dǎo)
- Mockito Essentials
- Web前端開發(fā)技術(shù):HTML、CSS、JavaScript
- INSTANT Premium Drupal Themes
- CISSP in 21 Days(Second Edition)
- 區(qū)塊鏈原理與技術(shù)應(yīng)用
- 機(jī)器學(xué)習(xí)開發(fā)者指南