Open Gerrit0 opened 2 years ago
Is this in reference to declaration emit, quick info (aka tooltips), or something else?
This is related to quick infos - declaration emit shows what I'd expect, preserving the keyof
for both types.
Personally, I'd prefer to see // ^? type Keys = "valuenum1" | "valuenum2" | "valuenum3" | "valuenum4" | "valuenum5" | "valuenum6"
most of the time. typeof X
in quick infos slows/distracts my ability to wrap my head around the types I'm investigating.
Another example of this where keyof
is not necessary:
crossbell.js has a 1400 line as const
array which is referenced in some types.
One of those places is in a method parameter
class CharacterContract {
// ...
async create(
{
owner,
handle,
metadataOrUri,
linkModule,
}: {
/** The Ethereum address of the character owner. */
owner: Address
/** The handle of the character you want to create. */
handle: string
/** The metadata or URI of the character. */
metadataOrUri: CharacterMetadata | string
linkModule?: MintOrLinkModuleConfig
},
overrides: WriteOverrides<Entry, 'createCharacter'> = {},
): Promise<Result<bigint, true>> {
When calling this function, TypeScript does not preserve the Entry
alias, which results in a hover which can't really be reasoned about:
Suggestion
π Search Terms
smarter type alias preservation, type query types
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
TypeScript 4.2 introduced intelligent type alias preservation for most union types. This greatly improved visibility when dealing with large union types. This preservation should be extended to union types created by via type query types.
Could probably also be considered a bug / missing edge case.
π Motivating Example
Playground link
Ref: https://github.com/TypeStrong/typedoc/issues/1867