Typescript and React setting initial state with empty typed array

前端 未结 3 1684
醉梦人生
醉梦人生 2021-02-12 16:00

Say I have the following snippet:

interface State {
  alarms: Alarm[];
}
export default class Alarms extends React.Component<{}, State> {
  state = {
    a         


        
3条回答
  •  时光取名叫无心
    2021-02-12 16:31

    Would

    alarms: [] as Alarm[]

    work for Typescript and for you ?

    See this question on how you can cast arrays in Typescript : TypeScript casting arrays

提交回复
热议问题