const state: StateType = {
user: 'User',
columns: [
{title: 'ToDo', cardList: []},
{title: 'In progress', cardList: []},
{title: 'Testing', cardList: []},
{title: 'Done', cardList: []},
],
cards: [],
}
interface StateType {
user: string,
columns: [
{title: string, cardList: []}
]
}Тип "[{ title: string; cardList: []; }, { title: string; cardList: []; }, { title: string; cardList: []; }, { title: string; cardList: []; }]" не может быть назначен для типа "[{ title: string; cardList: []; }]".
Число элементов в источнике — 4, но целевой объект разрешает только 1. [ {title: string, cardList: []} ] - это не массив, заполняемый значениями типа {title: string, cardList: []}, это кортеж из одного значения данного типа.Array<{title: string, cardList: []}> или так {title: string, cardList: []}[]. type ToDo = {title: 'ToDo', cardList: []}
type Testing = {title: 'Testing', cardList: []}
interface StateType {
user: string,
columns: (ToDo | Testing)[]
}
const state: StateType = {
user: 'User',
columns: [
{title: 'ToDo', cardList: []},
{title: 'Testing', cardList: []},
],
}enum kinds {
ToDo = 'ToDo',
Testing = 'Testing',
}
type Column = {title: kinds, cardList: []}
interface StateType {
user: string,
columns: Column[]
}
const state: StateType = {
user: 'User',
columns: [
{title: kinds.ToDo, cardList: []},
{title: kinds.Testing, cardList: []},
],
}