microsoft / microsoft/TypeScript

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

Aperta
#44,351 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@weswigham ci sta già lavorando.

Dal 2/6/2021.

Needs Investigation Rescheduled
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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 https://github.com/microsoft/TypeScript/commit/8ea4ec94967c9db8542ca229dedd656fe9e051df

⏯ 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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.