-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to expand mapped types #28508
Comments
@mjbvz could we perhaps expose consider exposing clickable "expando" ranges in quick info/signature help that fire a request to a new language server endpoint with a token associated with the range for expanded content for the range (and that expanded content may itself have more things which need expansion)? Off the top of my head, I can think of four places where this'd be useful:
cc @DanielRosenwasser and @RyanCavanaugh since I think we've mentioned this before. |
This might look like the expand feature as described in #34944? |
I just ran into this myself setting up similar code. I have a lot of conditional and mapped types that work wonderfully, but they unfortunately render intellisense unusable. Intellisense const Person: t.TsTypeToObjType<MapPropDefinitionsToTsTypes<MapPropDefinitionsToTsOptionalProperties<t.MapTsPropertiesToPropDefinitions<MapPropDefinitionsToTsTypes<MapPropDefinitionsToTsOptionalProperties<MapObjectDefParamsToPropDefinitions<{
type: t.Type<"string">;
}>>> & MapPropDefinitionsToTsTypes<...>, never>>> & MapPropDefinitionsToTsTypes<...>> type Person = {
type: LiteralType<"Person">;
name: Type<"string">;
age: Type<"number">;
} |
@akutruff You can use an |
Thanks for the suggestion. Unfortunately that didn't solve the problem. Only one property became simplified, but otherwise, it still has expanded noise. Edit: From your suggestion, I was able to find another thread #22575 (comment) with a similar approach. In my case, I have recursive types, and that was causing the issue! Here is a modified version that does trick, but it runs into the issue with potentially infinite recursion. #34933 (comment) type Id<T> = T extends object ? {} & { [P in keyof T]: Id<T[P]> } : T; |
I believe most of the pain in intellisense with regards to mapped types is because they're often passed inferred types that have no better name than their expanded form. Ordinarily, Typescript should display a type alias's name wherever possible, e.g. There's also currently no way in Typescript to provide a name for an inferred type. If the above problem were fixed and we were able to name inferred types, then we would be able to architect types whose naming actually communicates intent to developers clearly. I believe these would also provide natural points in intellisense where a developer could opt to 'step into' type expansion. I detail the problem and make a proposal for new syntax to name inferred types here: |
I want to be able to expand mapped type in intellisense
Currently, mapped types is displayed directly with the mapper and original type, which is unhelpful as hell
With the ts 2.8 condition type,
you can write more powerful declaration to map almost everything to correct type for you,
but the ide simply show it is mapped,
you don't know what is it actually mapped to.
for example, in the above case, I have a mapper looks like
that will transform the decalration to a simple
But the ide won't tell you anything, which is quite annoying
The text was updated successfully, but these errors were encountered: