Flattening types in generated .d.ts files for libraries #60647
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
π Search Terms
"delcaration readable" "declaration pretty"
β Viability Checklist
β Suggestion
Allow library authors to add the
inline
modifier on a type declaration which makes the compiler flatten the type in generated code.An
inline
modifier for type declarationsThe compiler would mostly ignore the
inline
directive (it would behave similarly to thePrettify
helper type, however, when building the declaration files, the compiler will generate the flattened version like thisAlternatively, instead of a modifier on a declaration, it can be a modifier we can add on types
Honestly, I'm not sure of the full semantics of
inline
. My mental intuition is based on thePrettify
type helper.Alternatively, a tsconfig.json setting might also work. Although I'm sure to have the best experience, the compiler might need some feedback from the library author too.
Sorry if this isn't fully fleshed out, but I'm willing to work on a full proposal in case the team is open to the idea.
π Motivating Example
We have a lot of computed types in our design system library. Most (React) components can receive Theme defined props.
Here's a verbatim example which is our
Box
component, which is a design system awarediv
.This describes the type perfectly, but it leads to very poor DX for the callers. When someone Cmd-Clicks
Box
, they see a type which isn't really helpful when trying to figure out the API ofBox
.What I'd like to see in the generated declarations would be something like the following

π» Use Cases
Improving the UX of our library consumers when there are computed types in the public API.
It's hard to understand the API of our library because cmputed types obscure the actual properties that are accepted by the types
We wrap certain public API types with the
Prettify
helper type so that the users can hover over certain types to received a flattened version of the typeThe text was updated successfully, but these errors were encountered: