From b7fcf161d54c8362e93fec6803349fadd39ec8b8 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 18 Aug 2015 13:14:19 -0700 Subject: [PATCH] Added the '[Symbol.toPrimitive]' method to the 'Date' interface. --- src/lib/es6.d.ts | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index 934aa9d0762..d1efb7ce6dc 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -87,8 +87,8 @@ interface SymbolConstructor { split: symbol; /** - * A method that converts an object to a corresponding primitive value.Called by the ToPrimitive - * abstract operation. + * A method that converts an object to a corresponding primitive value. + * Called by the ToPrimitive abstract operation. */ toPrimitive: symbol; @@ -622,6 +622,30 @@ interface Math { [Symbol.toStringTag]: string; } +interface Date { + /** + * Converts a Date object to a string. + */ + [Symbol.toPrimitive](hint: "default"): string; + /** + * Converts a Date object to a string. + */ + [Symbol.toPrimitive](hint: "string"): string; + /** + * Converts a Date object to a number. + */ + [Symbol.toPrimitive](hint: "number"): number; + /** + * Converts a Date object to a string or number. + * + * @param hint The strings "number", "string", or "default" to specify what primitive to return. + * + * @throws {TypeError} If 'hint' was given something other than "number", "string", or "default". + * @returns A number if 'hint' was "number", a string if 'hint' was "string" or "default". + */ + [Symbol.toPrimitive](hint: string): string | number; +} + interface RegExp { /** * Matches a string with a regular expression, and returns an array containing the results of