You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// redux has types included in it's npm package, no need to use @types
815
+
// redux has types included in it's npm package - don't install from @types
816
816
```
817
817
818
-
### - when to use `interface` and when `type` to behave consistently?
819
-
> Use `type` when declaring simple object literal structs e.g. Component Props, Component State, Redux State, Redux Action.
820
-
In other cases it's more flexible to use `interface` over `type` because interfaces can be implemented, extended and merged.
821
-
Related `ts-lint` rule: https://palantir.github.io/tslint/rules/interface-over-type-literal/
822
-
823
-
### - should I use React.PropTypes?
824
-
> No. In TypeScript it is completely unnecessary, you will get a much better free type checking and intellisense at compile time when declaring a "generic type" for component: `React.Component<{ myProp:string }, { myState:number}>`, this way you'll never get any runtime errors and get elegant way of describing component external API.
818
+
### - should I still use React.PropTypes in TS?
819
+
> No. In TypeScript it is unnecessary, when declaring Props and State types (refer to React components examples) you will get completely free intellisense and compile-time safety with static type checking, this way you'll be safe from runtime errors, not waste time on debugging and get an elegant way of describing component external API in your source code.
825
820
826
-
### - how to best declare component instance properties?
827
-
> Don't use old-school React class constructors way, prefer to use Property Initializers (first class support in TypeScript).
821
+
### - how to best initialize class instance or static properties?
822
+
> Prefered modern style is to use class Property Initializers
### - is it better to use `interface` or `type` as convention?
850
+
> In general this is a matter of taste, you can extend and implement type the same as an interface. The only major difference is that you will get a compiler error when extending and interface with incompatible properties, in contrary to merging types (&) operation, but otherwise they are synonymous.
851
+
Related `ts-lint` rule: https://palantir.github.io/tslint/rules/interface-over-type-literal/
0 commit comments