Skip to content

Instantly share code, notes, and snippets.

@littledan
Created December 4, 2017 18:12
Show Gist options
  • Save littledan/c456a2a0e54a3f629fea9d57e74f61d1 to your computer and use it in GitHub Desktop.
Save littledan/c456a2a0e54a3f629fea9d57e74f61d1 to your computer and use it in GitHub Desktop.
Should JavaScript use a header file format (a la WebIDL) to define its standard library?
@namespace
class Math {
static abs(x: Number): Number; // Types optional; provide cast on input and assertion on ouptut
@nonwritable
static LOG10E: Number;
// ...
}
@legacyPrototypeInstance
class Date {
// Overloads not included in JSIDL syntax
@callable
@length(7)
constructor();
static parse(str: String): Date;
@length(7)
static UTC( year: Number, @optional month: Number, @optional date: Number, @optional hours: Number, @optional minutes: Number, @optional seconds: Number, @optional ms: Number) : Number;
[[DateValue]]; // Internal slot declaration
[@@toPrimitive]();
getHours(): Number;
setHours(hour: Number, @optional min: Number, @optional sec: Number, @optional ms: Number): Number;
// ...
}
@namespace
class Intl {
// Complex type Locales calls CanonicalizeLocaleList as its cast
static Array getCanonicalLocales(locales: Locales);
}
@dictionary
class DateTimeFormatOptions {
@optional weekday: String;
@optional year: String;
@optional month: String;
@optional day: String;
@optional hour: String;
@optional minute: String;
@optional second: String;
// ...
}
@namespace(Intl)
class DateTimeFormat {
@legacyIntlBoundMethod
resolvedOptions();
static supportedLocalesOf(locales: Locales): Array;
get [@@toStringTag](): String;
formatToParts(date: Date): Array;
@legacyIntlBoundMethod
@legacyIntlMethodFallback
format(date: Date): String;
@legacyIntlMethodFallback
resolvedOptions(): DateTimeFormatOptions;
@legacyIntlConstructFallback
constructor(@optional locales: Locales, @optional options: DateTimeFormatOptions);
[[InitializedDateTimeFormat]];
[[Locale]];
[[Calendar]];
[[NumberingSystem]];
[[TimeZone]];
[[Weekday]];
[[Era]];
[[Year]];
[[Month]];
[[Day]];
[[Hour]];
[[Minute]];
[[Second]];
[[TimeZoneName]];
[[HourCycle]];
[[Pattern]];
[[BoundFormat]];
static [[AvailableLocales]];
static [[RelevantExtensionKeys]];
static [[LocaleData]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment