fix(types): fix import('echarts/types/dist/shared') in users' .d.ts can not visit 'echarts/types/dist/shared.d.ts' since v5.5.0 - #20030
Merged
Conversation
…sit `'echarts/types/dist/shared.d.ts'` since v5.5.0. Fix it. Fix #19663.
|
Thanks for your contribution! The pull request is marked to be To reviewers: If this PR is going to be described in the changelog in the future release, please make sure this PR has one of the following labels: This message is shown because the PR description doesn't contain the document related template. |
import('echarts/types/dist/shared') can not visit 'echarts/types/dist/shared.d.ts' since v5.5.0.import('echarts/types/dist/shared') can not visit 'echarts/types/dist/shared.d.ts' since v5.5.0.
Contributor
|
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-20030@a209486 |
Ovilia
approved these changes
Jun 14, 2024
|
Congratulations! Your PR has been merged. Thanks for your contribution! 👍 |
import('echarts/types/dist/shared') can not visit 'echarts/types/dist/shared.d.ts' since v5.5.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief Information
This pull request is in the type of:
What does this PR do?
Fix that In users' .d.ts
import('echarts/types/dist/shared')can not visit'echarts/types/dist/shared.d.ts'since v5.5.0.Fixed issues
Fix #19663 .
Relative issues: ecomfe/vue-echarts#766 , #19513
Details
Before: What was the problem?
In users' .d.ts
import('echarts/types/dist/shared')can not visit'echarts/types/dist/shared.d.ts'since v5.5.0.It cause that users can only get type
anywhen import echarts type.After: How does it behave after the fixing?
After some investigate to
tsc, I found that:Test case (tested in typescript v5.3.3 and v4.6.4) :
In the case about we can found that:
tscmay generate "inline import" (i.e.,import(xxx/xxx/xxx)) or not.tscmay intentionally generate inline import to avoid to handle name collision. see Somtimes generating inline imports for d.ts files instead of using globally imported symbols microsoft/TypeScript#30258 (comment) TS 3.7 generates inline imports for typing files (.d.ts) although the source contains imports at the top microsoft/TypeScript#36097 (comment).import(xxx/xxx/xxx), the pathxxx/xxx/xxxprobably goes deep into the file where the target type declared literally defined, but may not consider its visibility defined in "exports" field ofpackage.json.EChartsTypefrom the last sentenceexport let option = {} as EChartsType1;, andEChartsTypeis declared inecharts/types/dist/shared.d.ts, the final inline import isimport('echarts/types/dist/shared')orimport('echarts/types/dist/shared.js'), althoughecharts/types/dist/sharedseems to be a private file and imported byecharts/core.d.ts.tsc. It's verbose, just for the record:transformRoot,function symbolToTypeNodeis called to resolve the literal typeEChartsType1of the sentenceexport let option = {} as EChartsType1;,lookupSymbolChainis called to use the inputsymbol(of "EChartsType")to get a chain like[symbol(of "dist/shared.d.ts"), symbol(of "EChartsType")], and generate a specifier forchain[0], and callconst lit = factory.createLiteralTypeNode(factory.createStringLiteral(specifier));to create a literal node containing the path 'xxx/dist/shared', and callreturn factory.createImportTypeNode(lit, ...)to return a new type node on which the literal node is mounted.writeKeyword("import"); writePunctuation("("); emit(node.argument);the literal node of 'xxx/dist/shared' generated above is in thenode.argumentand be used to write asimport('xxx/dist/shared').ambient module declaration fileornormal module filehas the same behavior.import('echarts/types/dist/shared')orimport('echarts/types/dist/shared.js')can be generated bytsc.import('echarts/types/dist/shared.js'):"moduleResolution": "node"in "tsconfig.json".tsccan resolve it back toecharts/types/dist/shared.d.ts(tested in tsc v4.6.4 & v5.3.3).import('echarts/types/dist/shared'):"moduleResolution": "bundle"in "tsconfig.json".echarts/types/dist/sharedis not visible from outside. So this PR make it visible by add it to the "exports" field ofpackage.json.Other infomation
In https://cdn.jsdelivr.net/npm/vue-echarts@6.7.3/dist/index.d.ts there are both
import("echarts/types/dist/shared")andimport("echarts/types/dist/echarts"). It because in https://github.com/ecomfe/vue-echarts/blob/v6.7.3/src/types.ts#L2 both from 'echarts/core' and 'echarts'.It's OK, but it probably be better a little if all of them are
from 'echarts/core', @Justineo .In the user's vue project, after update the dependent echarts, if the type is still
anyin.vuefile in vscode, try to "> Vue: Restart Vue and TS servers"