1

I'm trying to figure out a way to get rid of this error "Property 'pending' of type 'boolean' is not assignable to 'string' index type"

I've found this stackoverflow: arbitrary type definition gives: Property 'x' of type 'boolean' is not assignable to string index type 'string'
it's not the exact same but I tried to take the logic and do something similar but no success.

Here is what I've tried so far

type MyObj<K extends keyof any> ={ [P in K]: Record<P, string> & { btnWrap: boolean } };
const asMyObj = <T extends MyObj<keyof T>>(myObj: T) => myObj;

let myObj31 = asMyObj({ key1: 'val1', pending: true});


// -------------


type InnerObj = {
  [key: string]: string | boolean;
  pending: boolean;
};


const myObj32: InnerObj = { pending: true, key1: { id: 'val1' }, key2: { id:'val2'} };

// -------------

type customType = {
  [key: string]: { id: string };
  pending: boolean;
};

const myObj33: customType = { pending: true, key1: { id: 'val1' }, key2: { id:'val2'} };

// Some of these taken from https://stackoverflow.com/questions/55244493/arbitrary-type-definition-gives-property-x-of-type-boolean-is-not-assignabl


Typescript Playground

Thanks for any help!

Ikura
  • 188
  • 1
  • 11
  • 1
    There's nothing great in TypeScript for the "rest index signature" use case, unfortunately. See the linked question and answers for more information. Taking your playground and the example at the top I could write [this version](https://tsplay.dev/Wk8rjw), but such things all have drawbacks without native TS support. – jcalz Jun 14 '23 at 03:35

0 Answers0