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

Filter throws error when using as const #193

Open
IanVS opened this issue Apr 3, 2024 · 0 comments
Open

Filter throws error when using as const #193

IanVS opened this issue Apr 3, 2024 · 0 comments

Comments

@IanVS
Copy link

IanVS commented Apr 3, 2024

I found a problem when using an object with readonly keys and accessing one of them dynamically. It's tough to explain, so here's a minimal example:

const test = {
  A: [{ key: 1 }, { key: 2 }],
  B: [{ key: 3 }, { key: 4 }],
} as const;

function check(x: 'A' | 'B') {
  test[x].filter(y => y.key > 1)
}

Results in an error:

Argument of type '<T>(y: T | undefined) => boolean' is not assignable to parameter of type 'BooleanConstructor'.
  Type '<T>(y: T | undefined) => boolean' provides no match for the signature 'new (value?: any): Boolean'.

If I remove ts-reset, remove as const, or access test.A directly, there is no error.

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

1 participant