1

I tried this:

export interface ITarifFeatures {
  key: string;
}


export interface ITarif {
   features: ITarifFeatures[];
}

Then I have create object based on interface:

let obj<ITarif> {
      name: "Базовый",
      description: "Подходит для...",
      currency: "A",
      price: 1.99,
      period: "Месяц",
      features: ["СМС уведомления"]
    };

But this property is wrong:

features: ["СМС уведомления"]

Also I tried:

export type ITarifFeatures = {
  key: string[];
}

export interface ITarif {
  name: string;
  description: string;
  currency: string;
  price: number;
  period: string;
  features: ITarifFeatures
}
2
  • 2
    features: string[] Commented Mar 30, 2019 at 7:37
  • That is right, but I want to use custom type for further extending properties Commented Mar 30, 2019 at 7:39

2 Answers 2

1

The interface type ITarifFeatures expects a property called key that you are not supplying, you are passing an instance of string type ["СМС уведомления"] in the array instead, so modify the code to this:

export interface ITarifFeatures {
  key: string;
}
export interface ITarif {
    features: ITarifFeatures[];
    [x: string]: any 
}

let itarif: ITarifFeatures = {key: "СМС уведомления"};
let obj: ITarif = {
      name: "Базовый",
      description: "Подходит для...",
      currency: "A",
      price: 1.99,
      period: "Месяц",
      features: [itarif]
};

Also, the ITarif type will only accept features property, but you are trying to supply more key-values to it. To circumvent it add an indexer [x: string]: any in the original interface.

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

Comments

1

String type != ITarifFeatures

What is need is an object like this:

{
    key:'blabla'
}

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.