Typescript: Property 'captureStackTrace' does not exist on type 'ErrorConstructor'.

Created on 19 Jul 2015  ·  6Comments  ·  Source: microsoft/TypeScript

I couldn't find more information on this bug by googling, so I will assume this is rather unusual.

While this doesn't ruin the compiling (thank you for that well thought design of "ignoring" errors when emitting), it is mostly an aesthetic issue.

I was porting the nodejs assert module to be an internal module, so that I can use it with other internal modules for testing purposes. Anyway, I wrote the following:

export interface IStackStartFunction {
  (actual: any, 
   expected: any, 
   message?: string,
   operator?: string,
   stackStartFunction?: (...args) => any): any;
}

export interface IAssertiorErrorOptions {
  name?: string;
  actual: any;
  expected: any;
  operator: string;
  message?: string;
  generatedMessage?: boolean;
  stackStartFunction?: IStackStartFunction;
}

export class AssertionError implements Error {
  public name: string;
  public message: string;

  constructor(public options: IAssertiorErrorOptions) {
    this.name = options.name = 'AssertionError';
    if (options.message) {
      options.message = options.message;
      options.generatedMessage = false;
    } else {
      options.message = getMessage(this);
      options.generatedMessage = true;
    }
    this.message = options.message;
    var stackStartFunction = options.stackStartFunction || fail;
    Error.captureStackTrace(this, stackStartFunction);
  }
}

It gives me the error:

assert.ts(102,13): error TS2339: Property 'captureStackTrace' does not exist on type 'ErrorConstructor'.

I noticed that supporting implementing types such as Error and other ES-6 specific types was added recently. I don't know enough about TypeScript internals to help with a PR.

Thanks for your time and help.

Question

Most helpful comment

That should probably be added to node.d.ts.

All 6 comments

@Mamsaac : did you resolve this? Why was this issue closed?

captureStackTrace is not a standard property, it is a v8-specific one. you should be able to add definition to it as:

interface ErrorConstructor {
    captureStackTrace(thisArg: any, func: any): void
}

That should probably be added to node.d.ts.

@DanielRosenwasser Did this land in the node types? Not working for me.

@amcdnl @Mamsaac This helped - https://github.com/Microsoft/TypeScript/issues/1168#issuecomment-219296751

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kyasbal-1994 picture kyasbal-1994  ·  3Comments

bgrieder picture bgrieder  ·  3Comments

blendsdk picture blendsdk  ·  3Comments

fwanicka picture fwanicka  ·  3Comments

weswigham picture weswigham  ·  3Comments