Skip to content

Commit 75826f0

Browse files
authoredJun 4, 2018
add small answer to types vs interface question
1 parent 5a79f68 commit 75826f0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed
 

‎README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,17 @@ class App extends React.Component<AppProps, AppState> {
268268
}
269269
```
270270

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.
272282

273283
[Something to add? File an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new).
274284

0 commit comments

Comments
 (0)
Please sign in to comment.