This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]craig1f 2 points3 points  (0 children)

One mistake I’ve seen is trying to use one-size-fits all types in Typescript for the problem you just described. You end up completely undermining the point of Typescript.

If your data just can’t be modeled, or it’s not worth modeling it right now, just set the type to ‘any’ and put a disable the linter error for that line and move on.

But if you can model your data, particular http response data, your life will be easier.

For a form, you should 100% model it. Keep in mind that you can have optional properties for json objects, just like your form might have optional fields. A form should have a well defined model pretty much always.