fix: improve type support for isolated dependencies in pnpm#289
fix: improve type support for isolated dependencies in pnpm#289mdjermanovic merged 11 commits intomainfrom
Conversation
| "extends": "./tsconfig.json", | ||
| "files": ["dist/esm/index.js"], | ||
| "compilerOptions": { | ||
| "allowImportingTsExtensions": true, |
There was a problem hiding this comment.
allowImportingTsExtensions is required for TypeScript to accept import statements from "./types.ts" in the generated dist/esm/index.js file:
/** @import * as _typests from "./types.ts"; */Another possibility to avoid allowImportingTsExtensions is importing from "./types.js" instead. This will work if a dummy file dist/esm/types.js is added to the package, similarly to what is done in eslint/markdown:
https://app.unpkg.com/@eslint/markdown@7.4.0/files/dist/esm/types.js
There was a problem hiding this comment.
Instead of copying this into every tsconfig.esm.json file, can we add it to ./tsconfig.json?
There was a problem hiding this comment.
I've added it to tsconfig.base.json, which is the base config extended by the various tsconfig.esm.json files in the package directories, via "./tconfig.json" < "../../tsconfig.base.json".
|
Is there a reason we can't do this? /** @import { ConfigObject as Config, LegacyConfigObject as LegacyConfig ) from "@eslint/core" */ |
The problem is that For example, this JSDoc comment: /** @import { ConfigObject as Config, LegacyConfigObject as LegacyConfig, Plugin, RuleConfig } from "@eslint/core"; */Compiles into: import type { ConfigObject as Config } from "@eslint/core";In this case, TypeScript even recognizes that |
nzakas
left a comment
There was a problem hiding this comment.
Just one suggestion and otherwise LGTM.
| "extends": "./tsconfig.json", | ||
| "files": ["dist/esm/index.js"], | ||
| "compilerOptions": { | ||
| "allowImportingTsExtensions": true, |
There was a problem hiding this comment.
Instead of copying this into every tsconfig.esm.json file, can we add it to ./tsconfig.json?
|
There's a merge conflict in |
It's fixed now after rebasing. |
|
@fasttime which packages should be released after this change? Per the diff, it looks like this would only trigger |
I think the packages affected by the changes in |
|
To fix just #283, |
mdjermanovic
left a comment
There was a problem hiding this comment.
I've verified that @nzakas's suggestion has been applied.
Prerequisites checklist
What is the purpose of this pull request?
This pull request, together with eslint/eslint#20201 in the main repo, fixes issue #283 by replacing
import()syntax inside JSDoc@typedeftags with local module aliases in the bundled.jsoutput.Before:
After
This has the effect of creating a type import (
import type *) in the generated .d.ts files:Before:
After
The type import doesn't change the exported types, but it overcomes a limitation of TypeScript when resolving types across symlinked directories. See also microsoft/TypeScript#62558.
The current change only affects packages built using the
dedupe-typestools:config-arrayconfig-helpersplugin-kitAnyway, these are not the only packages impacted by the TypeScript issue.
compatis widely used and it is also impacted:StackBlitz demo
This could be fixed in a follow-up pull request if necessary.
What changes did you make? (Give an overview)
dedupe-typesandbuild-ctstools to match the new format.Related Issues
fixes #283
Is there anything you'd like reviewers to focus on?