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
Copy file name to clipboardExpand all lines: README.md
+11-1
Original file line number
Diff line number
Diff line change
@@ -268,7 +268,17 @@ class App extends React.Component<AppProps, AppState> {
268
268
}
269
269
```
270
270
271
-
`interface`s are different from `type`s in Typescript, but for our purposes they do the same things. [read more](https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c)
271
+
[Something to add? File an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new).
272
+
273
+
## Types or Interfaces?
274
+
275
+
`interface`s are different from `type`s in Typescript, but they can be used for very similar things as far as common React uses cases are concerned. Here's a helpful rule of thumb:
276
+
277
+
- always use `interface` for public API's definition when authoring a library or 3rd party ambient type definitions.
278
+
279
+
- consider using `type` for your React Component Props and State, because it is more constrained.
280
+
281
+
[You can read more about the edge cases of using types and interfaces here](https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c). Note there have been significant changes since Typescript 2.1.
272
282
273
283
[Something to add? File an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new).
0 commit comments