microsoft / microsoft/TypeScript
IsolatedDeclarations: emitted declarations inconsistent between `transpileDeclaration` API and TypeScript Playground
@andrewbranch is already working on this.
Since Sep 23, 2024.
- 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
isolatedDeclarationandnoCheck
// 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
isolatedDeclarationandnoCheck
// 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
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.
Assessment
This issue has not been assessed yet.