標準のNode.jsライブラリの型定義では、インターフェイスDateConstructor
の定義が見つかりました。TypeScriptインターフェイスの署名 "():文字列"
interface DateConstructor {
new(): Date;
new(value: number): Date;
new(value: string): Date;
new(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date;
(): string;
readonly prototype: Date;
/**
* Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970.
* @param s A date string
*/
parse(s: string): number;
/**
* Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date.
* @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year.
* @param month The month as an number between 0 and 11 (January to December).
* @param date The date as an number between 1 and 31.
* @param hours Must be supplied if minutes is supplied. An number from 0 to 23 (midnight to 11pm) that specifies the hour.
* @param minutes Must be supplied if seconds is supplied. An number from 0 to 59 that specifies the minutes.
* @param seconds Must be supplied if milliseconds is supplied. An number from 0 to 59 that specifies the seconds.
* @param ms An number from 0 to 999 that specifies the milliseconds.
*/
UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number;
now(): number;
}
declare const Date: DateConstructor;
これには奇妙な定義(): string
が含まれています。どのように私はクラスで定義することができます、このインターフェイスを実装したいですか?
定義はクラスのコンストラクタもnew
なしと呼ばれる文字列を返す引数なしで呼び出し可能な関数であることを意味し:
[TypeScript:コンストラクタを使用した機能インターフェイス]の複製があります(https://stackoverflow.com/questions/46809986/typescript-functional-interface-with-constructor/46812163#46812163) – jcalz