Repository navigation
Type merging for imported types only works if the type is imported from "node_modules/@types/" dir #39691
Description
Activity
- addedNeeds More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified
on Jul 21, 2020 RyanCavanaugh commented
on Jul 21, 2020 MemberMore actionsIt's hard for us to guess about file layouts from prose; can you make a sample repo or zip file?
The layout is simple: a typings module with two files (vars.d.ts and index.d.ts, see their content above). The thing is if I symlink a dir with those files in
node_modules/@types, type merging works, but when the typings are plugged in via the "typeRoots" project options, the merging breaks. Except for the merging, the typings work fine in both configurations.RyanCavanaugh commented
on Jul 21, 2020 MemberMore actionsIt's hard for us to guess about file layouts from prose; can you make a sample repo or zip file?
Here is the real example where I discovered the problem: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/46236/files#diff-411587a1c5c471aa01bb2b97932f74f1R62
I'll try to create an MWE.
typescript-issue-39691-mwe.zip
Here is the MWE, please. Check out the
client/index.tsfile. To make it work, I doln -s ../../../types/typings-modulein theclient/node_modules/@types/dir.- addedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.and removedNeeds More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified
on Jul 21, 2020 - addedRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
on Dec 11, 2020 The issue here is that when the
typings-moduleis included through custom type root the user source file extending interface (extension.d.tsin the example) cannot resolve "typings-module" from that source file, so it does not merge those two things together.
The reason being module resolution does not take into account the custom type roots onlynode_modules/@typeswhich is what results in this. That issue is tracked by #37958 and is breaking change and i have been investigating this but it cannot be taken for 4.2.
Keeping this alive but marking for 4.35 remaining items
- linked a pull request that will close this issueUpdates to type reference directive resolution and module resolution when failed #51715
on Dec 1, 2022 - addedFix AvailableA PR has been opened for this issueA PR has been opened for this issue
on Dec 2, 2022
Consider the following example.
In typings_module:
vars.d.ts:
index.d.ts:
Now, we want to specify properties for the
UserPropertiesinterface.a_project_file.d.ts:
The bug is the type merging works only if the "typings_module" files are inside "node_modules/@types/" and does not work if the same files are referenced from another location via the "typeRoots" TSC option in "tsconfig.json".
TypeScript Version: 3.9.6
Search Terms: "type merging", "declaration files"