How to create an extension method in TypeScript for 'Date' data type
问题 I have tried to create an extension method in TypeScript based on this discussion ( https://github.com/Microsoft/TypeScript/issues/9 ), but I couldn't create a working one. Here is my code, namespace Mynamespace { interface Date { ConvertToDateFromTS(msg: string): Date; } Date.ConvertToDateFromTS(msg: string): Date { //conversion code here } export class MyClass {} } but its not working. 回答1: You need to change the prototype: interface Date { ConvertToDateFromTS(msg: string): Date; } Date