Closed
Description
openedon Dec 31, 2020
Bug Report
🔎 Search Terms
inlining duplication declaration emit optional union parameters
🕗 Version & Regression Information
- This is not a regression.
- This is a stylistic issue in emitted DTS. The code is correct.
- This is the behavior in every version I tried (3.3 ... nightly)
⏯ Playground Link
Playground link with relevant code
💻 Code
type u = 1 | 2 | 3 | 4 | 5;
export const o = {
mandatory(arg: u): void {arg}, // DTS references union (good)
optional(arg?: u): void {arg}, // DTS inlines union (bad)
}
🙁 Actual behavior
DTS emit expands the definition of the union for the optional parameter.
declare type u = 1 | 2 | 3 | 4 | 5;
export declare const o: {
mandatory(arg: u): void;
optional(arg?: 1 | 2 | 3 | 4 | 5 | undefined): void;
};
🙂 Expected behavior
DTS emit should treat it the same as a mandatory parameter and reference it by name.
declare type u = 1 | 2 | 3 | 4 | 5;
export declare const o: {
mandatory(arg: u): void;
optional(arg?: u): void;
};
Related Issues
This is a very specific instance of the issue of declarations inlining types. I'm raising it because it looks like a pure win to simplify emitted DTS files. Fixing this will make other userland tricks to simplify types more effective.
If fixing this is contentious, or requires a large overhaul, please feel free to immediately close. I will not be offend because I realize there is a long tail of issues in this space and do not wish to create noise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment