microsoft / microsoft/TypeScript
@ts-ignore on an import that gets redefined strips the import from output
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.7.5 and 3.8.0
Search Terms:
- ts-ignore remove import
- ts-ignore strip import
Code
// @ts-ignore: Local Foo override
import Foo from "foo";
declare const Foo: {
bar(): number;
}
Foo.bar();
Expected behavior:
JS output should probably be:
import Foo from "foo";
Foo.bar();
Actual behavior:
JS output is:
Foo.bar();
Related Issues: None so far
Additional remarks: We are aware of other ways to type the foo module but in this particular case the foo override needs to be done in the file using it. As far as we tried, adding a ts-ignore is the only way to make ts understand that we want to redefine the module.
Now, this seems to move the declaration site from the import to the the declare statement and that has the effect to mark the import site as unused, since the import is unused, ts strips it.
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 behavior from the provided TypeScript 3.7.5/3.8.0 code and Playground link, then trace the compiler's import-elision decision for an import followed by a redeclaration. Done means the emitted JavaScript retains the import as shown in the expected output, with coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100