Skip to content

Commit b7fcf16

Browse files
Added the '[Symbol.toPrimitive]' method to the 'Date' interface.
1 parent 2682703 commit b7fcf16

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

src/lib/es6.d.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ interface SymbolConstructor {
8787
split: symbol;
8888

8989
/**
90-
* A method that converts an object to a corresponding primitive value.Called by the ToPrimitive
91-
* abstract operation.
90+
* A method that converts an object to a corresponding primitive value.
91+
* Called by the ToPrimitive abstract operation.
9292
*/
9393
toPrimitive: symbol;
9494

@@ -622,6 +622,30 @@ interface Math {
622622
[Symbol.toStringTag]: string;
623623
}
624624

625+
interface Date {
626+
/**
627+
* Converts a Date object to a string.
628+
*/
629+
[Symbol.toPrimitive](hint: "default"): string;
630+
/**
631+
* Converts a Date object to a string.
632+
*/
633+
[Symbol.toPrimitive](hint: "string"): string;
634+
/**
635+
* Converts a Date object to a number.
636+
*/
637+
[Symbol.toPrimitive](hint: "number"): number;
638+
/**
639+
* Converts a Date object to a string or number.
640+
*
641+
* @param hint The strings "number", "string", or "default" to specify what primitive to return.
642+
*
643+
* @throws {TypeError} If 'hint' was given something other than "number", "string", or "default".
644+
* @returns A number if 'hint' was "number", a string if 'hint' was "string" or "default".
645+
*/
646+
[Symbol.toPrimitive](hint: string): string | number;
647+
}
648+
625649
interface RegExp {
626650
/**
627651
* Matches a string with a regular expression, and returns an array containing the results of

0 commit comments

Comments
 (0)