search

Home  >  Q&A  >  body text

How to limit the value type of FormGroup in ts?

I have a constant like this:

const defaultInfo: FormGroup = this.fb.group({
  id: 1,
  name: qian,
  amount: 123,
})

And I want to limit the types inside FormGroup, so I write like this:

interface InfoInterface {
  id: number,
  name: string,
  amount: number,
}


interface InfoFormGroup extends FormGroup {
  value: InfoInterface
}

const defaultInfo: InfoFormGroup = this.fb.group({
  id: 1,
  name: qian,
  amount: 123,
})

Apparently it doesn't work because no matter what I change the properties of the Info Interface to, there are no errors, why? How to limit the value type of FormGroup in ts

Restrict the value type of FormGroup in ts

P粉566048790P粉566048790500 days ago445

reply all(1)I'll reply

  • P粉378264633
  • Cancelreply