mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
19 lines
813 B
Plaintext
19 lines
813 B
Plaintext
cannotIndexGenericWritingError.ts(4,5): error TS2862: Type 'T' is generic and can only be indexed for reading.
|
|
cannotIndexGenericWritingError.ts(8,5): error TS2862: Type 'T' is generic and can only be indexed for reading.
|
|
|
|
|
|
==== cannotIndexGenericWritingError.ts (2 errors) ====
|
|
// From #47357
|
|
|
|
function foo<T extends Record<string | symbol, any>>(target: T, p: string | symbol) {
|
|
target[p] = ""; // error
|
|
~~~~~~~~~
|
|
!!! error TS2862: Type 'T' is generic and can only be indexed for reading.
|
|
}
|
|
|
|
function foo2<T extends number[] & { [s: string]: number | string }>(target: T, p: string | number) {
|
|
target[p] = 1; // error
|
|
~~~~~~~~~
|
|
!!! error TS2862: Type 'T' is generic and can only be indexed for reading.
|
|
target[1] = 1; // ok
|
|
} |