microsoft / microsoft/TypeScript
importing merged declorations in js files
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
### 🔎 Search Terms
is a type and cannot be imported in JavaScript files;
JSDoc;
Import;
Declaration Merging.
### 🕗 Version & Regression Information
- This is the behavior in every version I tried (v5.8.3 - Nightly)
### 💻 Code
```ts
// @filename: foo.impl.js
/**
* @import { Foo } from "./foo.js"
*/
/**
* @returns { Foo }
*/
export function alloc() {
return {
prop1: 42,
prop2: "lorem ipsum"
}
}
// @filename: foo.js
export * as Foo from "./foo.impl.js"
/**
* @typedef Foo
* @prop { number } prop1
* @prop { string } prop2
*/
// @filename: index.js
import { Foo } from "./foo.js"
// ^^^ 'Foo' is a type and cannot be imported in JavaScript files. Use 'import("./foo.js").Foo' in a JSDoc type annotation.ts(18042)
const foo = Foo.alloc();
```
### 🙁 Actual behavior
tsc/lsp emmits error
### 🙂 Expected behavior
no error
### Additional information about the issue
same example works fine using ts files
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example using foo.impl.js, foo.js, and index.js with tsc or the language service, then trace the diagnostic for the import of Foo and compare it with the working TypeScript-file case. Done means the JavaScript example reports no import error and Foo.alloc() remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100