microsoft / microsoft/TypeScript

IsolatedDeclarations: emitted declarations inconsistent between `transpileDeclaration` API and TypeScript Playground

Open
#60,031 2 comments 0 reactions 1 assignee View on GitHub

@andrewbranch is already working on this.

Since Sep 23, 2024.

Needs Investigation
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Acknowledgement
  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
Example

NOTE: Enabled isolatedDeclaration and noCheck

Playground Link

// input
import { Comment } from '@vue/runtime-core'
//       ^^^^^^^ https://github.com/vuejs/core/blob/a177092754642af2f98c33a4feffe8f198c3c950/packages/runtime-core/src/vnode.ts#L70
export const comment: Comment 

// .d.ts output
export declare const comment: Comment;

This example is correct because the tsc checker analyzer Comment is a const variable defined in @vue/runtime-core. So the Comment who referenced by comment is actually referenced lib.dom.d.ts's Comment. But the output of this example in transpileDeclaration APi will same as the following example.

Another example

NOTE: Enabled isolatedDeclaration and noCheck

Playground Link

// input
import { Comment } from 'does-not-exist'
export const comment: Comment 

// .d.ts output
import { Comment } from 'does-not-exist';
export declare const comment: Comment;

This example is also correct because the tsc checker can't analyze what Comment is, so the Comment was kept in the output as it has been referenced by comment.

But If I want to use lib.dom.d.ts's Comment rather than imported it will be incorrect.

Expect Behaviour

In IsolatedDeclarations, Ideally, we shouldn't analyze imports, but if we stop analyzing, this will generate incorrect output.

So I suggest tsc should throw an error about the above cases when IsolatedDeclarations is enabled. This is also beneficial for third-party IsolatedDeclarations implementations.

BTW this issue I found when I fix the output mismatch between oxc-isolated-declarations and tsc

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.