microsoft / microsoft/TypeScript

Cannot import javascript class in `index.d.ts` when using `jsconfig.json`

Open
#42,221 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Investigation
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.