Declaration emit may change type semantics when inlining conditional types #48140
Labels
Fix Available
A PR has been opened for this issue
Needs Investigation
This issue needs a team member to investigate its status.
Milestone
Bug Report
This issue was reported in a comment on #46655, but I'm making a separate issue for it since the other issue has a fix available that only covers the mapped type cases but not the conditional type cases.
🔎 Search Terms
conditional type over union
distributive conditional type
🕗 Version & Regression Information
v4.6.2
This is the behavior in every version I tried, and I reviewed the FAQ for entries about distributive conditional types.
⏯ Playground Link
Can't demonstrate in a single playground file.
💻 Code
🙁 Actual behavior
To repro this, you need to generate
api.d.ts
andinternal.d.ts
declaration files, and consume those fromtest.ts
. The three-file setup is the only way I could get tsc to inline the non-exported typePublicKeys2
in the .d.ts file. If you importapi.ts
directly from source, everything works as expected. Things only break when consuming from theapi.d.ts
file. So this issue is saying that the semantics of the emitted.d.ts
files is not the same as the sources they were emitted from.As shown in
test.ts
above, declaration emit type semantics change depending on whether an internal type is marked withexport
or not. In the above example, the declarations emitted forapi.d.ts
are:Specifically, the conditional type in
PublicKeys2
loses its distributivity the way it is inlined above, so the type's meaning changes.🙂 Expected behavior
Declaration emit semantics should be the same as the source code, regardless of whether or not
tsc
preserves an internal type in the emit, or expands it directly into a type expression.See also
#46655 (similar issue but for mapped types)
The text was updated successfully, but these errors were encountered: