Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my object desctructoring throwing a no string index signature error in typescript?

Given an object

const appConfig: {
    brands: {...},
    market: {...},
}

I try to destructure it in typescript via:

const {brand} =  appConfig.brand;

Which fails via:

src/partner/transform.ts(17,12): error TS2459: Type 'IBrandConfig' has no property 'brand' and no string index signature.
like image 231
k0pernikus Avatar asked Nov 23 '25 16:11

k0pernikus


1 Answers

It's a faulty object desctructor syntax. These will work as expected:

const {brand} =  appConfig;
const {brand, market} =  appConfig;

As they are a shortcut for:

const brand =  appConfig.brand;
const market =  appConfig.market;
like image 140
k0pernikus Avatar answered Nov 26 '25 11:11

k0pernikus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!