-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
ts-node gives type errors, presumably doesn't load .d.ts file, when allowJs && checkJs #1421
Comments
Might need to adjust |
I read in the FAQ that I need to fiddle with Does anyone know why |
@itsfarseen I think this error is unfortunately valid. The problem isn't within As for solutions, I don't have a good one right now. In theory the Edit: To clarify it's not related to |
Update: I was using the scope option wrong (trying to give it a directory instead of a boolean). This works for me:
You can also add this to your "ts-node": {
"scope": true
} |
@blakeembrey could you explain what is happening under the hood when |
I'm not really an expert on TypeScript when it comes to the JS features, but based on this I believe it's basically doing type-checking on your JavaScript (almost) as if it's TypeScript. |
Whenever you require a file and ts-node needs to compile it, the file is
manually added to the "files" array as needed to ensure TypeScript looks at
it and emits compiled code.
I suspect this is happening:
tsc will not look at the .js file because it has instead resolved to the
.d.ts file. ts-node, on the other hand, has seen a require() which
resolved to the js file, so it has forced the .js file to be included in
your "files" array.
tsc --listFiles will show the files pulled into compilation. tsc
--traceResolutions will explain why they are pulled into compilation.
*Above, "files" array refers to the array in tsconfig.json
…On Mon, Aug 9, 2021, 1:50 AM Blake Embrey ***@***.***> wrote:
I'm not really an expert on TypeScript when it comes to the JS features,
but based on this
<https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html> I
believe it's basically doing type-checking on your JavaScript (almost) as
if it's TypeScript.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1421 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OA3MJBHWY273PE5AL3T35UD7ANCNFSM5BXNYTRQ>
.
|
As far as I can tell, this has been solved so I'm going to close it. Please comment if the issue persists and if you think it's a ts-node bug. |
Expected Behavior
Code compiles.
Actual Behavior
Gives type error, saying variable implicitly has an
any
type.Steps to reproduce the problem
foo({foo:100})
tsc
, it compiles without any error.node --loader ts-node/esm main.ts
Output:
Minimal reproduction
https://github.com/itsfarseen/ts-node-repro
Specifications
tsconfig.json: https://github.com/itsfarseen/ts-node-repro/blob/main/myapp-bar/tsconfig.json
Operating system and version: Arch Linux
The text was updated successfully, but these errors were encountered: