Skip to content

[REGRESSION] Error is not instanceof error #25016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ninja- opened this issue Jun 16, 2018 · 5 comments
Closed

[REGRESSION] Error is not instanceof error #25016

ninja- opened this issue Jun 16, 2018 · 5 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@ninja-
Copy link

ninja- commented Jun 16, 2018

TypeScript Version: 2.9.2
NodeJS: 10.2.1

Search Terms:

Code

let net = require("net"); 1
let x = net.Socket(); 1
x.on('error', e => {
console.log(e instanceof Error, e);
}); 1
x.connect(1234); 1

Expected behavior:
Native node error from 'net' module is instanceof error
Actual behavior:
It works correctly via node, but not via typescript :(

Typescript:

# node ..\node_modules\ts-node\dist\bin.js
> let net = require("net"); 1
1
> let x = net.Socket(); 1
1
> x.on('error', e => {
... console.log(e instanceof Error, e);
... }); 1
1
> x.connect(1234); 1
1
> false { Error: connect ECONNREFUSED 127.0.0.1:1234
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1161:14)
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 1234 }

Node:

>node -i
> let net = require("net"); 1
1
> let x = net.Socket(); 1
1
> x.on('error', e => {
... console.log(e instanceof Error, e);
... }); 1
1
> x.connect(1234); 1
1
> true { Error: connect ECONNREFUSED 127.0.0.1:1234
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1161:14)
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 1234 }

Playground Link:

Related Issues:

@DanielRosenwasser
Copy link
Member

Hey, thanks for filing, but this seems to be a duplicate of #12123

https://github.com/Microsoft/TypeScript/wiki/FAQ#why-doesnt-extending-built-ins-like-error-array-and-map-work

In the future using the issue tracker's search functionality can make it easier for us to triage issues. Thanks!

@DanielRosenwasser
Copy link
Member

actually I'm reopening this because I'm not totally sure. But I think part of the cause is actually that you have ts-node running on Node internals targeting ES5 or earlier. Try targeting ES2015 and seeing if that helps.

@ninja-
Copy link
Author

ninja- commented Jun 16, 2018

Here is my tsconfig:

{
    "compilerOptions": {
        "outDir": "./lib/",
        "sourceMap": true,
        "noImplicitAny": true,
        "module": "commonjs",
        "target": "es2017",
        "jsx": "react",
        "lib": ["es2017"],
        "experimentalDecorators": true,
        "declaration": true,
        "emitDecoratorMetadata": true
    },
    "include": [
      "./src/**/*",
      "./__tests__"
    ]
}

Also I am sure it's being loaded by ts-node...
I don't run ts-node on prod., but I am using Jest+ts-node for unit tests and "instanceof Error" not working breaks the application logic...

@mhegazy
Copy link
Contributor

mhegazy commented Jun 19, 2018

Looks like a ts-node issue. please file this under https://github.com/TypeStrong/ts-node/issues instead

@mhegazy mhegazy added the External Relates to another program, environment, or user action which we cannot control. label Jun 19, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

4 participants