Skip to content

Commit af6a565

Browse files
committed
Merge pull request #45 from tsriram/typescript-case
Use right case for TypeScript
2 parents b6101a7 + 4673688 commit af6a565

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ I thought I should lay out some core principles that we will follow so that this
66

77
1. **We are a CHEATSHEET above all**: all examples to be as simple as possible, easily searched, and presented for copy-and-paste.
88
2. **Collapsible explanations**: No more than 1-2 sentences of explanation, any more than that we put inside `details` tags.
9-
3. **React + Typescript ONLY**: React's ecosystem is huge, we can't possibly cover it all. This includes Redux. Would encourage people to maintain separate lists for stuff like React + Apollo Graphql, for example.
9+
3. **React + TypeScript ONLY**: React's ecosystem is huge, we can't possibly cover it all. This includes Redux. Would encourage people to maintain separate lists for stuff like React + Apollo Graphql, for example.
1010

1111
That's all I've got! Again, really happy you are thinking about helping out, who knows, the person who you might be helping is yourself in future!

README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
:wave: This repo is maintained by [@swyx](https://twitter.com/swyx) and [@IslamAttrash](https://twitter.com/IslamAttrash), we're so happy you want to try out Typescript with React! This is meant to be an intermediate guide for React developers familiar with the concepts of Typescript but who are just getting started writing their first React + Typescript apps. If you see anything wrong or missing, please [file an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new)! :+1:
2+
:wave: This repo is maintained by [@swyx](https://twitter.com/swyx) and [@IslamAttrash](https://twitter.com/IslamAttrash), we're so happy you want to try out TypeScript with React! This is meant to be an intermediate guide for React developers familiar with the concepts of TypeScript but who are just getting started writing their first React + TypeScript apps. If you see anything wrong or missing, please [file an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new)! :+1:
33

44
Translations: [中文翻译](https://github.com/fi3ework/blog/tree/master/react-typescript-cheatsheet-cn) *maintained by [@fi3ework](https://github.com/fi3ework/blog/tree/master/react-typescript-cheatsheet-cn)*
55

@@ -11,7 +11,7 @@ Translations: [中文翻译](https://github.com/fi3ework/blog/tree/master/react-
1111

1212
- [Section 1: Setup](#section-1-setup)
1313
* [Prerequisites](#prerequisites)
14-
* [React + Typescript Starter Kits](#react--typescript-starter-kits)
14+
* [React + TypeScript Starter Kits](#react--typescript-starter-kits)
1515
* [Import React](#import-react)
1616
- [Section 2: Getting Started](#section-2-getting-started)
1717
* [Stateless Functional Components](#stateless-functional-components)
@@ -29,16 +29,16 @@ Translations: [中文翻译](https://github.com/fi3ework/blog/tree/master/react-
2929
* [Portals](#portals)
3030
* [Error Boundaries](#error-boundaries)
3131
* [Timeout/Placeholder/createFetcher](#timeoutplaceholdercreatefetcher))
32-
- [Section 4: Useful Patterns by Typescript Version](#section-4-useful-patterns-by-typescript-version)
33-
* [Typescript 2.9](#typescript-29)
34-
* [Typescript 3.0](#typescript-30)
32+
- [Section 4: Useful Patterns by TypeScript Version](#section-4-useful-patterns-by-typescript-version)
33+
* [TypeScript 2.9](#typescript-29)
34+
* [TypeScript 3.0](#typescript-30)
3535
- [Section 5: Misc. Concerns](#section-5-misc-concerns)
36-
* [Writing Typescript Libraries instead of Apps](#writing-typescript-libraries-instead-of-apps)
36+
* [Writing TypeScript Libraries instead of Apps](#writing-typescript-libraries-instead-of-apps)
3737
* [Component/Design System Development](#componentdesign-system-development)
3838
* [Migrating from Flow](#migrating-from-flow)
3939
* [Prettier + TSLint](#prettier--tslint)
4040
* [ESLint + TSLint](#eslint--tslint)
41-
* [Working with Non-Typescript Libraries (writing your own index.d.ts)](#working-with-non-typescript-libraries-writing-your-own-indexdts)
41+
* [Working with Non-TypeScript Libraries (writing your own index.d.ts)](#working-with-non-typescript-libraries-writing-your-own-indexdts)
4242
- [Troubleshooting Handbook: Types](#troubleshooting-handbook-types)
4343
* [Union types](#union-types)
4444
* [Optional Types](#optional-types)
@@ -50,8 +50,8 @@ Translations: [中文翻译](https://github.com/fi3ework/blog/tree/master/react-
5050
* [Type Zoo](#type-zoo)
5151
- [Troubleshooting Handbook: TSLint](#troubleshooting-handbook-tslint)
5252
- [Troubleshooting Handbook: tsconfig.json](#troubleshooting-handbook-tsconfigjson)
53-
- [Recommended React + Typescript codebases to learn from](#recommended-react--typescript-codebases-to-learn-from)
54-
- [Other React + Typescript resources](#other-react--typescript-resources)
53+
- [Recommended React + TypeScript codebases to learn from](#recommended-react--typescript-codebases-to-learn-from)
54+
- [Other React + TypeScript resources](#other-react--typescript-resources)
5555
- [My question isn't answered here!](#my-question-isnt-answered-here)
5656

5757
</details>
@@ -61,11 +61,11 @@ Translations: [中文翻译](https://github.com/fi3ework/blog/tree/master/react-
6161
## Prerequisites
6262

6363
1. good understanding of [React](https://reactjs.org)
64-
2. familiarity with [Typescript Types](https://www.typescriptlang.org/docs/handbook/basic-types.html)
65-
3. having read [the Typescript section in the official React docs](https://reactjs.org/docs/static-type-checking.html#typescript).
64+
2. familiarity with [TypeScript Types](https://www.typescriptlang.org/docs/handbook/basic-types.html)
65+
3. having read [the TypeScript section in the official React docs](https://reactjs.org/docs/static-type-checking.html#typescript).
6666
4. (optional) Read Microsoft's [TypeScript-React-Starter](https://github.com/Microsoft/TypeScript-React-Starter#typescript-react-starter) docs.
6767

68-
## React + Typescript Starter Kits
68+
## React + TypeScript Starter Kits
6969

7070
1. based on `create-react-app`
7171

@@ -80,10 +80,10 @@ Translations: [中文翻译](https://github.com/fi3ework/blog/tree/master/react-
8080
> In your command line: `create-react-app my-app --scripts-version=@jpavon/react-scripts-ts`
8181
8282

83-
2. <https://github.com/sw-yx/create-react-app-parcel-typescript> sets up a React + Typescript app with Parcel :)
84-
3. <https://github.com/basarat/typescript-react/tree/master/01%20bootstrap> for manual setup of React + Typescript + Webpack + Babel
83+
2. <https://github.com/sw-yx/create-react-app-parcel-typescript> sets up a React + TypeScript app with Parcel :)
84+
3. <https://github.com/basarat/typescript-react/tree/master/01%20bootstrap> for manual setup of React + TypeScript + Webpack + Babel
8585

86-
In particular, make sure that you have `@types/react` and `@types/react-dom` installed. [Read more about the DefinitelyTyped project if you are unfamiliar](https://definitelytyped.org/). There are also many React + Typescript boilerplates, please see [our Resources list below](https://github.com/sw-yx/react-typescript-cheatsheet#recommended-react--typescript-codebases-to-learn-from).
86+
In particular, make sure that you have `@types/react` and `@types/react-dom` installed. [Read more about the DefinitelyTyped project if you are unfamiliar](https://definitelytyped.org/). There are also many React + TypeScript boilerplates, please see [our Resources list below](https://github.com/sw-yx/react-typescript-cheatsheet#recommended-react--typescript-codebases-to-learn-from).
8787

8888
## Import React
8989

@@ -92,7 +92,7 @@ import * as React from 'react';
9292
import * as ReactDOM from 'react-dom';
9393
```
9494

95-
In [TypeScript 2.7+](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html), you can run Typescript with `--allowSyntheticDefaultImports` (or add `"allowSyntheticDefaultImports": true` to tsconfig) to import like in regular jsx:
95+
In [TypeScript 2.7+](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html), you can run TypeScript with `--allowSyntheticDefaultImports` (or add `"allowSyntheticDefaultImports": true` to tsconfig) to import like in regular jsx:
9696

9797
```tsx
9898
import React from 'react';
@@ -145,7 +145,7 @@ const Title: React.SFC<{ title: string }> = ({ children, title }) => (
145145

146146
## Stateful Class-based Components
147147

148-
Within Typescript, `React.Component` is a generic type (aka `React.Component<PropType, StateType>`), so you actually want to provide it with prop and (optionally) state types:
148+
Within TypeScript, `React.Component` is a generic type (aka `React.Component<PropType, StateType>`), so you actually want to provide it with prop and (optionally) state types:
149149

150150
```tsx
151151
class App extends React.Component<{
@@ -306,13 +306,13 @@ class App extends React.Component<AppProps, AppState> {
306306

307307
## Types or Interfaces?
308308

309-
`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:
309+
`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:
310310

311311
- always use `interface` for public API's definition when authoring a library or 3rd party ambient type definitions.
312312

313313
- consider using `type` for your React Component Props and State, because it is more constrained.
314314

315-
[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.
315+
[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.
316316

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

@@ -548,17 +548,17 @@ This example is based on the [Event Bubbling Through Portal](https://reactjs.org
548548

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

551-
# Section 4: Useful Patterns by Typescript Version
551+
# Section 4: Useful Patterns by TypeScript Version
552552

553-
Typescript Versions often introduce new ways to do things; this section helps current users of React + Typescript upgrade Typescript versions and explore patterns commonly used by Typescript + React apps and libraries. This may have duplications with other sections; if you spot any discrepancies, [file an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new)!
553+
TypeScript Versions often introduce new ways to do things; this section helps current users of React + TypeScript upgrade TypeScript versions and explore patterns commonly used by TypeScript + React apps and libraries. This may have duplications with other sections; if you spot any discrepancies, [file an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new)!
554554

555-
*Typescript version guides before 2.9 are unwritten, please feel free to send a PR!*
555+
*TypeScript version guides before 2.9 are unwritten, please feel free to send a PR!*
556556

557-
## Typescript 2.9
557+
## TypeScript 2.9
558558

559559
*To be completed.*
560560

561-
## Typescript 3.0
561+
## TypeScript 3.0
562562

563563
[[Release Notes](https://github.com/Microsoft/TypeScript/releases/tag/v3.0.1) | [Blog Post](https://blogs.msdn.microsoft.com/typescript/2018/07/30/announcing-typescript-3-0/)]
564564

@@ -601,11 +601,11 @@ For typing API's to force type checks - *should we include this?*
601601

602602
# Section 5: Misc. Concerns
603603

604-
Sometimes writing React isn't just about React. While we don't focus on other libraries like Redux (see below for more on that), here are some tips on other common concerns when making apps with React + Typescript.
604+
Sometimes writing React isn't just about React. While we don't focus on other libraries like Redux (see below for more on that), here are some tips on other common concerns when making apps with React + TypeScript.
605605

606-
## Writing Typescript Libraries instead of Apps
606+
## Writing TypeScript Libraries instead of Apps
607607

608-
`propTypes` may seem unnecessary with TypeScript, especially when building React + Typescript **apps**, but they are still relevant when writing **libraries** which may be used by developers working in Javascript.
608+
`propTypes` may seem unnecessary with TypeScript, especially when building React + TypeScript **apps**, but they are still relevant when writing **libraries** which may be used by developers working in Javascript.
609609

610610
```ts
611611
interface IMyComponentProps {
@@ -763,7 +763,7 @@ npm i -D typescript-eslint-parser
763763

764764
An example github repository with a project showing how to integrate [eslint + tslint + create-react-app-ts](https://github.com/azdanov/tslint-eslint-crats).
765765

766-
## Working with Non-Typescript Libraries (writing your own index.d.ts)
766+
## Working with Non-TypeScript Libraries (writing your own index.d.ts)
767767

768768
*Not written yet.*
769769

@@ -773,7 +773,7 @@ Please contribute on this topic! [We have an ongoing issue here with some refere
773773

774774
# Troubleshooting Handbook: Types
775775

776-
Facing weird type errors? You aren't alone. This is the worst part of using Typescript with React. Try to avoid typing with `any` as much as possible to experience the full benefits of typescript. Instead, let's try to be familiar with some of the common strategies to solve these issues.
776+
Facing weird type errors? You aren't alone. This is the worst part of using TypeScript with React. Try to avoid typing with `any` as much as possible to experience the full benefits of typescript. Instead, let's try to be familiar with some of the common strategies to solve these issues.
777777

778778
## Union types
779779

@@ -827,7 +827,7 @@ This is not yet written. Please PR or [File an issue](https://github.com/sw-yx/r
827827

828828
## Enum Types
829829

830-
Enums in Typescript default to numbers. You will usually want to use them as strings instead:
830+
Enums in TypeScript default to numbers. You will usually want to use them as strings instead:
831831

832832
```tsx
833833
export enum ButtonSizes {
@@ -860,13 +860,13 @@ export declare type Position = 'left' | 'right' | 'top' | 'bottom';
860860

861861
<summary>Explanation</summary>
862862

863-
This is handy because Typescript will throw errors when you mistype a string for your props.
863+
This is handy because TypeScript will throw errors when you mistype a string for your props.
864864

865865
</details>
866866

867867
## Type Assertion
868868

869-
Sometimes Typescript is just getting your type wrong, or union types need to be asserted to a more specific type to work with other APIs, so assert with the `as` keyword. This tells the compiler you know better than it does.
869+
Sometimes TypeScript is just getting your type wrong, or union types need to be asserted to a more specific type to work with other APIs, so assert with the `as` keyword. This tells the compiler you know better than it does.
870870

871871
```tsx
872872
class MyComponent extends React.Component<{
@@ -1071,7 +1071,7 @@ Please open an issue and discuss if there are better recommended choices. I like
10711071

10721072
# Troubleshooting Handbook: Bugs in official typings
10731073

1074-
If you run into bugs with your library's official typings, you can copy them locally and tell Typescript to use your local version using the "paths" field. In your `tsconfig.json`:
1074+
If you run into bugs with your library's official typings, you can copy them locally and tell TypeScript to use your local version using the "paths" field. In your `tsconfig.json`:
10751075

10761076
```json
10771077
{
@@ -1108,7 +1108,7 @@ const f = (e: PlotlyHTMLElement) => { e.removeAllListeners(); }
11081108
This is not yet written. Please PR or [File an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new) with your suggestions!
11091109
</details>
11101110

1111-
# Recommended React + Typescript codebases to learn from
1111+
# Recommended React + TypeScript codebases to learn from
11121112

11131113
- https://github.com/jaredpalmer/formik
11141114
- https://github.com/jaredpalmer/react-fns
@@ -1129,12 +1129,12 @@ React Native Boilerplates: *contributed by [@spoeck](https://github.com/sw-yx/re
11291129
- https://github.com/emin93/react-native-template-typescript
11301130
- <https://github.com/Microsoft/TypeScript-React-Native-Starter>
11311131

1132-
# Other React + Typescript resources
1132+
# Other React + TypeScript resources
11331133

11341134
- me! <https://twitter.com/swyx>
11351135
- <https://github.com/piotrwitek/react-redux-typescript-guide> - **HIGHLY HIGHLY RECOMMENDED**, i wrote this repo before knowing about this one, this has a lot of stuff I don't cover, including **REDUX** and **JEST**.
1136-
- [Ultimate React Component Patterns with Typescript 2.8](https://levelup.gitconnected.com/ultimate-react-component-patterns-with-typescript-2-8-82990c516935)
1137-
- [Basarat's Typescript gitbook has a React section](https://basarat.gitbooks.io/typescript/content/docs/jsx/react.html) with an Egghead.io course as well.
1136+
- [Ultimate React Component Patterns with TypeScript 2.8](https://levelup.gitconnected.com/ultimate-react-component-patterns-with-typescript-2-8-82990c516935)
1137+
- [Basarat's TypeScript gitbook has a React section](https://basarat.gitbooks.io/typescript/content/docs/jsx/react.html) with an Egghead.io course as well.
11381138
- [Charles Bryant's gitbook](https://charleslbryant.gitbooks.io/hello-react-and-typescript/content/) 2yrs old and on the more basic side but has sample code and IDE advice.
11391139
- [TypeScript React Starter Template by Microsoft](https://github.com/Microsoft/TypeScript-React-Starter) A starter template for TypeScript and React with a detailed README describing how to use the two together.
11401140
- [You?](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new).

0 commit comments

Comments
 (0)