diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 8893a7b0bb6..24e2c489197 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -966,7 +966,7 @@ declare var Error: ErrorConstructor; interface EvalError extends Error { } -interface EvalErrorConstructor { +interface EvalErrorConstructor extends ErrorConstructor { new(message?: string): EvalError; (message?: string): EvalError; readonly prototype: EvalError; @@ -977,7 +977,7 @@ declare var EvalError: EvalErrorConstructor; interface RangeError extends Error { } -interface RangeErrorConstructor { +interface RangeErrorConstructor extends ErrorConstructor { new(message?: string): RangeError; (message?: string): RangeError; readonly prototype: RangeError; @@ -988,7 +988,7 @@ declare var RangeError: RangeErrorConstructor; interface ReferenceError extends Error { } -interface ReferenceErrorConstructor { +interface ReferenceErrorConstructor extends ErrorConstructor { new(message?: string): ReferenceError; (message?: string): ReferenceError; readonly prototype: ReferenceError; @@ -999,7 +999,7 @@ declare var ReferenceError: ReferenceErrorConstructor; interface SyntaxError extends Error { } -interface SyntaxErrorConstructor { +interface SyntaxErrorConstructor extends ErrorConstructor { new(message?: string): SyntaxError; (message?: string): SyntaxError; readonly prototype: SyntaxError; @@ -1010,7 +1010,7 @@ declare var SyntaxError: SyntaxErrorConstructor; interface TypeError extends Error { } -interface TypeErrorConstructor { +interface TypeErrorConstructor extends ErrorConstructor { new(message?: string): TypeError; (message?: string): TypeError; readonly prototype: TypeError; @@ -1021,7 +1021,7 @@ declare var TypeError: TypeErrorConstructor; interface URIError extends Error { } -interface URIErrorConstructor { +interface URIErrorConstructor extends ErrorConstructor { new(message?: string): URIError; (message?: string): URIError; readonly prototype: URIError; diff --git a/tests/baselines/reference/errorConstructorSubtypes.js b/tests/baselines/reference/errorConstructorSubtypes.js new file mode 100644 index 00000000000..a04c4abf85b --- /dev/null +++ b/tests/baselines/reference/errorConstructorSubtypes.js @@ -0,0 +1,18 @@ +//// [errorConstructorSubtypes.ts] +// In Node, ErrorConstructor is augmented with extra properties. Excerpted below. +interface ErrorConstructor { + captureStackTrace(targetObject: Object, constructorOpt?: Function): void; +} + +declare var x: ErrorConstructor +x = Error; // OK +x = RangeError; +new x().message +x.captureStackTrace + + +//// [errorConstructorSubtypes.js] +x = Error; // OK +x = RangeError; +new x().message; +x.captureStackTrace; diff --git a/tests/baselines/reference/errorConstructorSubtypes.symbols b/tests/baselines/reference/errorConstructorSubtypes.symbols new file mode 100644 index 00000000000..7afbc9690be --- /dev/null +++ b/tests/baselines/reference/errorConstructorSubtypes.symbols @@ -0,0 +1,35 @@ +=== tests/cases/compiler/errorConstructorSubtypes.ts === +// In Node, ErrorConstructor is augmented with extra properties. Excerpted below. +interface ErrorConstructor { +>ErrorConstructor : Symbol(ErrorConstructor, Decl(lib.es5.d.ts, --, --), Decl(errorConstructorSubtypes.ts, 0, 0)) + + captureStackTrace(targetObject: Object, constructorOpt?: Function): void; +>captureStackTrace : Symbol(ErrorConstructor.captureStackTrace, Decl(errorConstructorSubtypes.ts, 1, 28)) +>targetObject : Symbol(targetObject, Decl(errorConstructorSubtypes.ts, 2, 20)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>constructorOpt : Symbol(constructorOpt, Decl(errorConstructorSubtypes.ts, 2, 41)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +} + +declare var x: ErrorConstructor +>x : Symbol(x, Decl(errorConstructorSubtypes.ts, 5, 11)) +>ErrorConstructor : Symbol(ErrorConstructor, Decl(lib.es5.d.ts, --, --), Decl(errorConstructorSubtypes.ts, 0, 0)) + +x = Error; // OK +>x : Symbol(x, Decl(errorConstructorSubtypes.ts, 5, 11)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + +x = RangeError; +>x : Symbol(x, Decl(errorConstructorSubtypes.ts, 5, 11)) +>RangeError : Symbol(RangeError, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + +new x().message +>new x().message : Symbol(Error.message, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(errorConstructorSubtypes.ts, 5, 11)) +>message : Symbol(Error.message, Decl(lib.es5.d.ts, --, --)) + +x.captureStackTrace +>x.captureStackTrace : Symbol(ErrorConstructor.captureStackTrace, Decl(errorConstructorSubtypes.ts, 1, 28)) +>x : Symbol(x, Decl(errorConstructorSubtypes.ts, 5, 11)) +>captureStackTrace : Symbol(ErrorConstructor.captureStackTrace, Decl(errorConstructorSubtypes.ts, 1, 28)) + diff --git a/tests/baselines/reference/errorConstructorSubtypes.types b/tests/baselines/reference/errorConstructorSubtypes.types new file mode 100644 index 00000000000..fe2fc6360fd --- /dev/null +++ b/tests/baselines/reference/errorConstructorSubtypes.types @@ -0,0 +1,33 @@ +=== tests/cases/compiler/errorConstructorSubtypes.ts === +// In Node, ErrorConstructor is augmented with extra properties. Excerpted below. +interface ErrorConstructor { + captureStackTrace(targetObject: Object, constructorOpt?: Function): void; +>captureStackTrace : (targetObject: Object, constructorOpt?: Function) => void +>targetObject : Object +>constructorOpt : Function +} + +declare var x: ErrorConstructor +>x : ErrorConstructor + +x = Error; // OK +>x = Error : ErrorConstructor +>x : ErrorConstructor +>Error : ErrorConstructor + +x = RangeError; +>x = RangeError : RangeErrorConstructor +>x : ErrorConstructor +>RangeError : RangeErrorConstructor + +new x().message +>new x().message : string +>new x() : Error +>x : ErrorConstructor +>message : string + +x.captureStackTrace +>x.captureStackTrace : (targetObject: Object, constructorOpt?: Function) => void +>x : ErrorConstructor +>captureStackTrace : (targetObject: Object, constructorOpt?: Function) => void + diff --git a/tests/cases/compiler/errorConstructorSubtypes.ts b/tests/cases/compiler/errorConstructorSubtypes.ts new file mode 100644 index 00000000000..1e64ea099cd --- /dev/null +++ b/tests/cases/compiler/errorConstructorSubtypes.ts @@ -0,0 +1,11 @@ +// @lib: es5,dom +// In Node, ErrorConstructor is augmented with extra properties. Excerpted below. +interface ErrorConstructor { + captureStackTrace(targetObject: Object, constructorOpt?: Function): void; +} + +declare var x: ErrorConstructor +x = Error; // OK +x = RangeError; +new x().message +x.captureStackTrace