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

Ambient reference silently included in all files #58911

Closed
cuttin-n-pastin opened this issue Jun 18, 2024 · 4 comments
Closed

Ambient reference silently included in all files #58911

cuttin-n-pastin opened this issue Jun 18, 2024 · 4 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@cuttin-n-pastin
Copy link

πŸ”Ž Search Terms

ambient reference

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries

⏯ Playground Link

https://github.com/cuttin-n-pastin/tsjsdocref-repro

πŸ’» Code

[package.json]

{
  "name": "repro",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "tsc": "tsc --noEmit"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "typescript": "^5.4.5"
  }
}

[tsconfig.json]

{
  "include": ["*.js"],
  "compilerOptions": {
    "types": [],
    "paths": {
      "*": ["./*.js"]
    },
    "moduleDetection": "force",
    "target": "es2021",
    "module": "commonjs",
    "lib": ["ES2022"],
    "allowJs": true,
    "outDir": "./dist",
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true                       ,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true
  }
}

[types/index.d.ts]

declare type MyType = 'foo' | 'bar' | 'baz';

[f1.js]

/// <reference types="./types" />

/** @type {MyType} */
const f = 'foo';

[f2.js]

// @ts-check

/** @type {MyType} */
const f = 'oof';

πŸ™ Actual behavior

f2.js:4:7 - error TS2322: Type '"oof"' is not assignable to type 'MyType'.

4 const f = 'oof';
        ~


Found 1 error in f2.js:4

πŸ™‚ Expected behavior

f2.js:3:12 - error TS2304: Cannot find name 'MyType'.

3 /** @type {MyType} */
             ~~~~~~


Found 1 error in f2.js:3

Additional information about the issue

No response

@jakebailey
Copy link
Member

jakebailey commented Jun 18, 2024

Reference directives are just another way to include a file in a project; they do not have the power to make ambient types only visible in a single file.

@cuttin-n-pastin
Copy link
Author

cuttin-n-pastin commented Jun 18, 2024

Thank you for your answer. The existing documentation does not make that clear.

What can I use to reference specific ambient types per .js file (that uses JSDoc syntax)?

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Jun 18, 2024
@RyanCavanaugh
Copy link
Member

There isn't a way to do that; you'd need separate tsconfigs

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants