microsoft / microsoft/TypeScript
Cannot import javascript class in `index.d.ts` when using `jsconfig.json`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
🔎 Search Terms
JSDoc, javascript, import, index.d.ts, jsconfig
🕗 Version & Regression Information
v4.1.2
⏯ Playground Link
Requires multiple files ( https://github.com/optoolco/components/blob/master/index.d.ts )
💻 Code
// index.d.ts
import * as toaster from "./toaster"
declare global {
interface HTMLElementTagNameMap {
"tonic-toaster": toaster.TonicToaster;
}
}
🙁 Actual behavior
Expected toaster.TonicToaster to exist and for document.querySelector('tonic-toaster') to work.
🙂 Expected behavior
toaster.TonicToaster is any, however when subclasses it, it works as expected
// index.d.ts
import * as toaster from "./toaster"
class CTonicToaster extends toaster.TonicToaster {}
declare global {
interface HTMLElementTagNameMap {
"tonic-toaster": CTonicToaster;
}
}
The goal here is for const t = document.querySelector('tonic-toaster') to work. When subclassing in the index.d.ts it works as expected including intellisense and go to definition for methods like toaster.create({})
When using "tonic-toaster": toaster.TonicToaster the querySelector("tonic-toaster") returns type any instead.
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
Start by reproducing the issue with the multiple files in the linked example: index.d.ts, ./toaster, and jsconfig.json. Compare the direct toaster.TonicToaster mapping with the subclass workaround, then verify document.querySelector("tonic-toaster") has the expected type and IntelliSense behavior when the issue is fixed.
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