Skip to content

Instantly share code, notes, and snippets.

@martian17
Last active March 18, 2023 23:37
Show Gist options
  • Save martian17/03b7933ca4d3b981c2c8895831ec5d82 to your computer and use it in GitHub Desktop.
Save martian17/03b7933ca4d3b981c2c8895831ec5d82 to your computer and use it in GitHub Desktop.
Testing code from stackoverflow
// 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