Skip to content

Error has different types in browser and in node.js #4807

Closed

Description

@psnider

In the browser, Error has a minimal interface. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error

But in node.js, Error includes the stack property. See https://nodejs.org/api/errors.html#errors_javascript_errors

So when I annotate existing node.js code such as:

new Error('oops').stack

tsc issues an error:

t.ts(1,19): error TS2339: Property 'stack' does not exist on type 'Error'.

This is correct for the browser, but incorrect for node.js.
If you cut and past the above code into the node REPL, node prints the stack trace for the error.

I thought this might be handled by tsc with a configuration parameter, but I couldn't find one.

Did I find a bug, or is there some corrective action I should take?

Activity

  1. mhegazy commented on Sep 15, 2015

    @mhegazy
    Contributor

    this looks like a typings issue on the node.d.ts side.

    defining this in one of your files should do the trick:

    interface Error {
        stack: string;
    }
  2. added
    Question
    on Sep 15, 2015
  3. psnider commented on Sep 16, 2015

    @psnider
    Author

    Thanks. That works.
    I'll issue a Pull Request on DT...

  4. psnider commented on Sep 16, 2015

    @psnider
    Author
  5. vvakame commented on Sep 20, 2015

    @vvakame
    Contributor

    it merged! 👍

  6. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions