Last active
March 18, 2023 23:37
-
-
Save martian17/03b7933ca4d3b981c2c8895831ec5d82 to your computer and use it in GitHub Desktop.
Testing code from stackoverflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source: https://stackoverflow.com/questions/72669756/property-selected-of-type-boolean-is-not-assignable-to-string-index-type | |
interface Field { | |
selected: boolean; | |
value: any; | |
} | |
type ConflictingVersionModel = { | |
[key: string]: Field; | |
} & { selected: boolean }; | |
const cvm: ConflictingVersionModel = { | |
asdf: { | |
selected:true, | |
value:3 | |
}, | |
qrwer: { | |
selected:true, | |
value:3 | |
}, | |
selected:true | |
}; | |
/* | |
tsc error: | |
test.ts:12:7 - error TS2322: Type '{ asdf: { selected: true; value: number; }; qrwer: { selected: true; value: number; }; selected: true; }' is not assignable to type 'ConflictingVersionModel'. | |
Type '{ asdf: { selected: true; value: number; }; qrwer: { selected: true; value: number; }; selected: true; }' is not assignable to type '{ [key: string]: Field; selected: boolean; }'. | |
Property 'selected' is incompatible with index signature. | |
Type 'boolean' is not assignable to type 'Field'. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment