Skip to content

Poor quick info due to erroneously deferring keyof T since #51621 #61728

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

Open
LukeAbby opened this issue May 19, 2025 · 2 comments
Open

Poor quick info due to erroneously deferring keyof T since #51621 #61728

LukeAbby opened this issue May 19, 2025 · 2 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@LukeAbby
Copy link

πŸ”Ž Search Terms

quick info, hover hint, deferred keyof

πŸ•— Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.3#code/C4TwDgpgBAQghgZwJYGMDCB7AdgEycJbOAGwB4AVAPigF4oBrCEDAMynKggA9gJcEocLCABQUKAH4owAE4BXCGKgAuKCxIIIAbhEjQkKJiwskAc1pQA3lBkQAVhBTA0xDJtWyFUAL4790cggEYFolIxNzbl5+K28lcSlLePEU2wcnFzcIVXhkdGw8AiIycLNKHRSUuMrVLAgANwgZHT1waAAle0dnV00LQOCAbQAiNO7MzWGAXR0AelmUgD0pRmY2UsiePhwBIRBJaXloVXViTSA

πŸ’» Code

type BasicConditional<T> = keyof T extends any
  ? true
  : false;

type Config = { rejectClose: true };
type Test =
  Config extends {}
    ? {
        rejectClose: BasicConditional<Config>;
      }
    : never;

type RejectClose = Test["rejectClose"];
//   ^? keyof Config extends any ? true : false

πŸ™ Actual behavior

RejectClose's quick info is keyof Config extends any ? true : false which is un-simplified and rather ugly.

πŸ™‚ Expected behavior

RejectClose should be simplified to just true in this case.

Additional information about the issue

No response

@Andarist
Copy link
Contributor

I'm working on the fix 🫑

@LukeAbby
Copy link
Author

@Andarist found that this is apparently more severe than I had expected:

type BasicConditional<T> = keyof T extends infer R ? R : never;

type Config = { rejectClose: true };

type Test = Config extends {}
  ? {
      rejectClose: BasicConditional<Config>;
    }
  : never;

const test: Test["rejectClose"] = "rejectClose";
//    ^ Type 'string' is not assignable to type 'BasicConditional<Config>'.

const ok: BasicConditional<Config> = "rejectClose"; // No error

It appears that this can actually break assignability!

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels May 19, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants