1

I've been trying to implement an extended interface with fields that are inserted after fetching data from the API.

My interfaces:

Blocks.d.ts
export interface InputsEntity {
    features: Features;
    commitment: string;
}

SingleBlock.d.ts
export interface Inputs extends InputsEntity {
    group: string;
    size: number;
    color: string;
}

In my react side:

const inputsData: Inputs[] = inputs.map((i:InputsEntity) => {
        i.size = inputs.length;
        i.color = '#F97C0C';
        return i as Inputs
    });

An error is coming up: Property 'size' does not exist on type 'InputsEntity'.

I'm guessing I'm not mapping this properly, any help or direction will be appreciated!

1 Answer 1

2
const inputsData: Inputs[] = inputs.map((i:InputsEntity) => {
        const temp: Inputs = {
          size: inputs.length,
          color: '#F97C0C',
          ...i
        };
        return temp;
    });

type InputsEntity is not compatible with Inputs because it lacks of property size, group and color. but you can return a new Inputs type value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.