Skip to content
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

Inferred type equivalent to #167

Closed
danvk opened this issue Sep 29, 2023 · 0 comments · Fixed by #252
Closed

Inferred type equivalent to #167

danvk opened this issue Sep 29, 2023 · 0 comments · Fixed by #252

Comments

@danvk
Copy link
Owner

danvk commented Sep 29, 2023

#145 added support for "equivalent to" assertions for type aliases. But what about values?

interface ABC { a: string; b: string; c: string; }
function foo(abc: ABC) {
  let k: keyof ABC;
  for (k in abc) {
    // ^? let k: keyof ABC (equivalent to "a" | "b" | "c")
  }
}
@danvk danvk added this to the Effective TypeScript 2nd Edition milestone Mar 7, 2024
danvk added a commit that referenced this issue Mar 10, 2024
Fixes #167 

Weirdly the `Resolve` helper only resolves types at the top level, not
in functions:

```ts
interface Point {
  x: number;
  y: number;
}

type Resolve<Raw> = Raw extends Function ? Raw : { [K in keyof Raw]: Raw[K] };
function foo(pt: Point) {
  let k: keyof Point;
  for (k in pt) {
    // ^? let k: keyof Point
    type SynthK = Resolve<keyof Point>;
    //   ^? type SynthK = keyof Point
  }
}

type SynthT2 = Resolve<keyof Point>;
//   ^? type SynthT2 = "x" | "y"`);
```

This might be microsoft/TypeScript#49852
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant