Element implicitly has an 'any' type because expression of type 'string' can't be used to index type
@weswigham đang làm issue này rồi.
Từ ngày 2/6/2021.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 106
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/TypeScript
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
microsoft/TypeScript#64322 · 2 bình luận · 1 reaction · 2 người được giao ·
-
Possible Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/TypeScript#64278 · 1 bình luận · 1 reaction ·
-
Docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
microsoft/TypeScript#64118 · 1 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
microsoft/TypeScript#64094 ·
-
Docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
microsoft/TypeScript#63959 · 5 bình luận ·
Tất cả issue của microsoft/TypeScript
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
modelcontextprotocol/registry#1654 ·
-
Type/Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OpenNSW/nsw-srilanka#497 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
milvus-io/birdwatcher#545 ·
-
kind/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
kubernetes-sigs/prow#953 · 1 bình luận ·