-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Could not find declaration when path mapping the root dir #39639
Comments
When importing a .js file, if the type definition file (d.ts) does not exist, it is implicitly set to any treatment. If you set "noImplicitAny" to true in tsconfig.json, you get a compile error. If you do not change this tsconfig.json, create a definition file with the same file name (test.d.ts) . You can compile in a terminal to generate a definition file as well, with
I hope your program works well! |
my func.ts file is already a typescript file. It would seem redundant to create an extra definition file for it. even if i do it though and now i have the following files in my root directory: test.ts doing setting or unsetting no implicit any doesnt seem to do anything in my case. Thanks again! |
Sorry. I misunderstood the problem. The cause of this error is the file position of the require statement after the transpile is not correct. The require("/func") after the transpile searches for the system root, so my In the local environment, the compile error is solved by placing the func.ts file directly under the D drive. done. The solution is to change the file notation to a relative path (./func) from func.ts, or you need to fix it with webpack or module-alias, where path conversion does not exist in Typescript. Thank you! |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
root/
tsconfig.json
"baseUrl": ".", "paths": { "/*": ["./*"] },
if i do
import func from "/func"
orimport func from "func.js"
in my test.ts everything works fine. However if i doimport func "/func.js"
i suddenly getCould not find a declaration file for module ... implicitly has an 'any' type.
Thanks in advance
The text was updated successfully, but these errors were encountered: