You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got an application that consumes two libraries like so:
The problem I'm facing is that the TypeScript build for LibB is outputting a collapsed "snapshot" of a union type that is imported from LibA rather than preserving a reference to the externally-defined union type. Because of this, when the application is using a newer version of LibA, the application cannot use types from the union that do not exist in the older version referenced by LibB.
As a workaround, I can update LibB to use the newer version of LibA, publish a new version, and update App to point to it, but since the implementation of LibB does not need to be updated, this step should be unnecessary.
I believe there have been various past proposals to solve this (such as in #35654), as well as a workarounds for specific use cases, but I haven't found a workaround that solves this particular case.
Thank you!
🔎 Search Terms
preserve type alias
prevent union type collapse
🕗 Version & Regression Information
v4.5.4, and other recent versions.
⏯ Playground Link
Because this issue only occurs when a project uses the emitted declarations from another project, I may not be able to provide a playground link.
💻 Code
# LibA (as of v1.1.0)
export type TypeFromLibA = "a" | "b";
# LibA (as of v1.5.0)
export type TypeFromLibA = "a" | "b" | "c";
# LibB
import type TypeFromLibA from "lib-a"; // ex. as npm library
export const functionFromLibB = (val: TypeFromLibA) => {
...
}
🙁 Actual behavior
# App
import functionFromLibB from "lib-b";
functionFromLibB("a"); // OK
functionFromLibB("c"); // Argument of type '"c"' is not assignable to parameter of type '"a" | "b"'.ts(2345)
🙂 Expected behavior
# App
import myFunction from "lib-b";
myFunction("a"); // OK
myFunction("c"); // OK
The text was updated successfully, but these errors were encountered:
This should work fine in any package manager that sets up node_modules correctly (with 1.5 in the parent and 1.1 as a subfolder of B), which is now "all of them". If not, please open a new issue with a concrete repo we can clone and investigate. Thanks!
Bug Report
I've got an application that consumes two libraries like so:

The problem I'm facing is that the TypeScript build for
LibB
is outputting a collapsed "snapshot" of a union type that is imported fromLibA
rather than preserving a reference to the externally-defined union type. Because of this, when the application is using a newer version ofLibA
, the application cannot use types from the union that do not exist in the older version referenced byLibB
.As a workaround, I can update
LibB
to use the newer version ofLibA
, publish a new version, and updateApp
to point to it, but since the implementation ofLibB
does not need to be updated, this step should be unnecessary.I believe there have been various past proposals to solve this (such as in #35654), as well as a workarounds for specific use cases, but I haven't found a workaround that solves this particular case.
Thank you!
🔎 Search Terms
preserve type alias
prevent union type collapse
🕗 Version & Regression Information
v4.5.4, and other recent versions.
⏯ Playground Link
Because this issue only occurs when a project uses the emitted declarations from another project, I may not be able to provide a playground link.
💻 Code
🙁 Actual behavior
🙂 Expected behavior
The text was updated successfully, but these errors were encountered: