lets say I have
type DataItems = {
id: number;
title: string;
subItems?: Array<DataItemChild>;
checked: boolean;
isEdit:boolean;
};
I defined an object as
const myObj = {} as DataItems;
when I inspect myObj I see {}.
I was expectiong:
{
id: 0,
title: '',
subItems:[],
checked: false,
isEdit:false
}
I could define my objest as :
const myObj = {
id : 0,
title: '',
subItems: [],
checked: false,
isEdit: false,
} as DataItems;
But I wonder is there a way to get this as default without manually needing to define it?
aswhen possible. tryconst myObj: DateItems = {}. So will Typescript will throw an error that you are missing some props. To your question: not that im aware of.