Skip to content

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type #44351

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
FreeSlave opened this issue May 31, 2021 · 1 comment
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@FreeSlave
Copy link

Bug Report

The following code used to work on 4.2.3, but does not build with 4.3.2, reporting the error on the last line

type ObjectFixedKeys<T extends object> = {
    [K in keyof T]: string extends K ? never : K
} extends { [_ in keyof T]: infer U }
    ? U
    : never

type DistributeKeysUnion<U> = U extends string
    ? { [K in U]: any }
    : never

type ObjectDictionaryKeys<T extends object> = Exclude<
    T,
    DistributeKeysUnion<ObjectFixedKeys<T>>
    >

type Condition = { $and: Array<Condition> }
    | { $or: Array<Condition> }
    | { [member: string]: string }

type O = ObjectFixedKeys<Condition>
type D = DistributeKeysUnion<ObjectFixedKeys<Condition>>

declare const s: string
type CT = ObjectDictionaryKeys<Condition>
declare const ct : CT
const h = ct[s]

Error:

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'CT'.
  No index signature with a parameter of type 'string' was found on type 'CT'.

🕗 Version & Regression Information

I tracked the regression to the version 4.3.0-dev.20210422

Probably related to 8ea4ec9

⏯ Playground Link

Playground link with relevant code

Note how the last line is evaluated to never, however if you select version 4.2.3 it gets evaluated to "foo" | "bar" as expected.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jun 2, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.4.0 (Beta) milestone Jun 2, 2021
@weswigham
Copy link
Member

Related: #44143 ? Looks like the same type at the core, anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

No branches or pull requests

5 participants