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

Indexed type using in #9

Closed
ersimont opened this issue May 13, 2021 · 1 comment
Closed

Indexed type using in #9

ersimont opened this issue May 13, 2021 · 1 comment

Comments

@ersimont
Copy link

Hello, and thank you for the expect-type library!

I ran into what might be an issue. Or maybe I misunderstand something. Should these pass:

    const normal: { [x: string]: Date } = {};
    const usingIn: { [x in string]: Date } = {};
    expectTypeOf(normal).toEqualTypeOf(usingIn);
    expectTypeOf(usingIn).toEqualTypeOf(normal);

They both show this error:

TS2345: Argument of type '{ [x: string]: Date; }' is not assignable to parameter of type 'never'.

@mmkal
Copy link
Owner

mmkal commented Jul 22, 2021

Hi @ersimont - thanks for the report. I hadn't considered this case, but my first instinct is to say that .toEqualTypeOf should be as strict as possible in any doubt. So I am ok with the fact these showing an error for now.

A couple other things worth noting:

  • .toMatchTypeOf passes in both cases
  • the typescript-eslint rule consistent-indexed-object-style autofixes normal in your example with Record<string, Date> which makes the tests as you have them show no errors, so arguably if following "best practices" this is a non-issue.

You have highlighted a UX problem though - the error message could be more helpful. Unfortunately TypeScript doesn't currently allow for dynamic type errors (see mmkal/ts#152) so in general there is some debugging required when expect-type finds any errors. But I'll keep this open and see if I can find a way to make the error message give a better hint of where to start looking/what it's actually highlighting.

@mmkal mmkal transferred this issue from mmkal/ts Sep 25, 2022
@mmkal mmkal closed this as completed May 10, 2023
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

No branches or pull requests

2 participants