You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have configured custom-resolved paths ~/* -> ~/src in tsconfig.json
In file errors/classes.ts we define custom error class AppError which extends Error
And we throw it in moreCode/code.ts file in function runCode
errors/errorHanlder runs this function in try/catch and here is the issue:
If i'm trying to check if err instanceof AppError - i will get false, however i used this class when throwing. After that i initialize the Error line after and it has correct constructor and therefore instanceof works there.
Looking at produced compiled js I see that file errorHandler.js imports var classes_1 = require("./classes"); however code.ts has another import path var classes_1 = require("~/errors/classes"); (I expect it's correct behavior). But looking at this instanceof example I assume that these two imports resolve module classes.ts twice as two different modules which is incorrect 👯♂️
Will appreaciate any ideas how to fix that!
The text was updated successfully, but these errors were encountered:
nsine
changed the title
instanceof doesn't work when using different kind of imports
Different import paths for same module resolve it to two different modules
Apr 20, 2020
Hey there 👋
TLDR;
I have created a small project to show the issue: https://github.com/nsine/tsconfig-paths-bug-example 🙂
Description:
~/*
->~/src
intsconfig.json
errors/classes.ts
we define custom error classAppError
which extendsError
moreCode/code.ts
file in functionrunCode
errors/errorHanlder
runs this function intry/catch
and here is the issue:If i'm trying to check if
err instanceof AppError
- i will getfalse
, however i used this class when throwing. After that i initialize the Error line after and it has correctconstructor
and thereforeinstanceof
works there.Looking at produced compiled js I see that file
errorHandler.js
importsvar classes_1 = require("./classes");
howevercode.ts
has another import pathvar classes_1 = require("~/errors/classes");
(I expect it's correct behavior). But looking at thisinstanceof
example I assume that these two imports resolve moduleclasses.ts
twice as two different modules which is incorrect 👯♂️Will appreaciate any ideas how to fix that!
The text was updated successfully, but these errors were encountered: