Skip to content
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

import "os" compiles even if types is set to [] in tsconfig.json #59010

Closed
rhysd opened this issue Jun 25, 2024 · 4 comments
Closed

import "os" compiles even if types is set to [] in tsconfig.json #59010

rhysd opened this issue Jun 25, 2024 · 4 comments

Comments

@rhysd
Copy link
Contributor

rhysd commented Jun 25, 2024

🔎 Search Terms

is:issue is:open types empty tsconfig label:Bug

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about all sections under 'Common "Bugs" That Aren't Bugs'
  • I was unable to test this on prior versions because _______

⏯ Playground Link

No response

💻 Code

Create a new npm project and add the dependencies:

npm init
npm install --save-dev typescript @types/node

Create tsconfig.json in the same directory:

{
  "compilerOptions": {
    "target": "es2022",
    "module": "nodenext",
    "strict": true,
    "types": []
  },
  "include": [
    "index.ts"
  ]
}

And write index.ts:

import 'os';

🙁 Actual behavior

npx tsc -p . compiles with no errors.

🙂 Expected behavior

npx tsc -p . should raise an error since types is empty.

index.ts:1:8 - error TS2307: Cannot find module 'os' or its corresponding type declarations.

1 import 'os';
         ~~~~

Found 1 error in index.ts:1

Additional information about the issue

When modifying the import statement in index.ts as follows,

import {} from 'os';

tsc reports an error as expected:

index.ts:1:16 - error TS2307: Cannot find module 'os' or its corresponding type declarations.

1 import {} from 'os';
                 ~~~~

Found 1 error in index.ts:1
@MartinJohns
Copy link
Contributor

This is working as intended. See this comment: #58725 (comment)

These imports are canonically unchecked by design.

@rhysd
Copy link
Contributor Author

rhysd commented Jun 25, 2024

I see. Thank you for the quick response. This is a workaround for supporting code like import "./some.css". Can we limit the behavior only when importing relative paths (starting with ./ or ../) so that we can limit the bad effect of the workaround as minimal as possible?

@jakebailey
Copy link
Member

jakebailey commented Jun 25, 2024

That would be very inconsistent.

More likely would be #58941 (once I formally propose it).

This issue is a dupe of #50394 in any case.

@rhysd
Copy link
Contributor Author

rhysd commented Jun 25, 2024

Okay. Thank you for the clear answer. Closing.

@rhysd rhysd closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants