https://i.imgur.com/NhC4ifB.png
Why is that not giving a error in vscode? even though it does on compilation. path hasn't been imported/defined
50 messages · Page 1 of 1 (latest)
https://i.imgur.com/NhC4ifB.png
Why is that not giving a error in vscode? even though it does on compilation. path hasn't been imported/defined
looks like it's been declared to ts, do you have any excess d.ts files for example?
maybe check Right Click > Go to Definition
or perhaps vscode is missing a tsconfig
yeah that option isnt there
negative, although all my interfaces are placed in there own types.ts which shouldnt be an issue i believe
How would that happen? there is a tsconfig in the root dir
is Go to References there?
or anything else related?
Yes, refrences are there. wait one
Also another weird thing is that ts server things i am redeclaring imports from libs? when the original imports it refers to are in different files
uh, references to path?
are the files missing imports and exports?
do you have esm imports/exports there
*do the files have no imports and no exports
I am using the default tsconfig, "noImplicitAny" set to true
wait one
Ok so the redclaration is a topic for another thread, i will get the info you asked in a second
This specific one? yeah it does.
All of them? no as i am switching from js to ts.
if you're doing this in node, then you should already have imports/exports between everything?
those still are imports/exports, just not esm imports/exports
I though you were refering to esm imports/exports only as imports/exports
just to be clear, you can still use cjs with ts, just that ts imports/exports look like esm imports/exports
Right.
imports and exports of what?
anything
if there are no imports and exports, TS thinks the file isn't a module
and so all its variables are implicitly global
There is indeed a file with no export, only imports
the file giving the issue has both
you say any types of import/export cjs/esm should make it work, correct?
i changed the only file defining path and fs from cjs to esm and them seemed to reolve the issue
although i would like to understand it
Is there a tsconfig option to disable this?
it's not exactly that you changed to esm, it's that you changed to the esm-like ts imports/exports which ts sees and understands is a module
i think there's some confusion going on here but if by this message you meant you were literally writing stuff like require() and module.exports = in your .ts files then there "are no imports and exports" according to TS
so the file wasn't being treated as a module
if you instead were writing import ... and export ... statements and letting tsc compile them down to require() and module.exports = , then that's different story
(you should basically always be doing this, even if you're only ever planning to target cjs)
Yeah, I mentioned it above, some of my files still had those as I was shifting from js to ts.
ah, it wasn't clear if "changing from cjs to esm" meant you were changing the module setting in the compiler or rewriting your code manually
Well I learned a nice thing today, about non module stuff being set to global
i don't think there's a tsconfig setting but i usually just slap export {} at the bottom of the file if it happens to have no "natural" imports/exports but i want it to be treated as a module anyway
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.