Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
36189a1
Added `React.ComponentProps<typeof Component>
piotrwitek Jan 24, 2019
533ea05
Added missing quote
piotrwitek Jan 24, 2019
92c9a5c
Add the example for useContext (#127)
sosukesuzuki Jan 26, 2019
38ccf55
Add useState example (#128)
sosukesuzuki Jan 26, 2019
446654f
Add examples for Context API (#129)
sosukesuzuki Jan 26, 2019
cbe31d9
Adds imports in module decleration
arshadkazmi42 Jan 30, 2019
fa0d274
README_SOURCE update and README generated using script
arshadkazmi42 Jan 30, 2019
23764a8
Added `React.ComponentProps<typeof Component>
piotrwitek Jan 24, 2019
d0e76f6
Added missing quote
piotrwitek Jan 24, 2019
bb8c555
Adds imports in module decleration
arshadkazmi42 Jan 30, 2019
b32ad8b
README_SOURCE update and README generated using script
arshadkazmi42 Jan 30, 2019
e592043
Merge branch 'master' into import-decleration
arshadkazmi42 Feb 3, 2019
dae1c72
Merge branch 'import-decleration' of github.com:arshadkazmi42/react-r…
arshadkazmi42 Feb 3, 2019
e602f90
Added `React.ComponentProps<typeof Component>
piotrwitek Jan 24, 2019
69756f2
Added missing quote
piotrwitek Jan 24, 2019
4da6157
Adds imports in module decleration
arshadkazmi42 Jan 30, 2019
b12c89f
README_SOURCE update and README generated using script
arshadkazmi42 Jan 30, 2019
a3facd0
Merge branch 'import-decleration' of github.com:arshadkazmi42/react-r…
arshadkazmi42 Feb 3, 2019
bdec1e5
Updated tests to fix build Closed #95 (#133)
piotrwitek Feb 3, 2019
8ccc7c8
Adds imports in module decleration
arshadkazmi42 Jan 30, 2019
9ee8c3f
README_SOURCE update and README generated using script
arshadkazmi42 Jan 30, 2019
e32c653
Added `React.ComponentProps<typeof Component>
piotrwitek Jan 24, 2019
05fd17f
Added missing quote
piotrwitek Jan 24, 2019
943e259
Merge branch 'import-decleration' of github.com:arshadkazmi42/react-r…
arshadkazmi42 Feb 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Issues can be funded by anyone and the money will be transparently distributed t
- [Recipes](#recipes)
- [Baseline tsconfig.json](#baseline-tsconfigjson)
- [Default and Named Module Exports](#default-and-named-module-exports)
- [Imports in Module Decleration](#imports-in-module-decleration)
- [Type Augmentation for npm libraries](#type-augmentation-for-npm-libraries)
- [Override type-definitions for npm libraries](#override-type-definitions-for-npm-libraries)
- [FAQ](#faq)
Expand Down Expand Up @@ -109,7 +110,7 @@ class MyComponent extends React.Component<Props, State> { ...
```

#### `React.ComponentProps<typeof Component>`
Gets type of Component Props, so you don't need to export Props from your component ever! (Works for both FC and Class components)
Gets component Props type. You don't no need to export Props from your component ever!
```tsx
type MyComponentProps = React.ComponentProps<typeof MyComponent>;
```
Expand Down Expand Up @@ -1135,41 +1136,45 @@ export default combineReducers<TodosState, TodosAction>({
### Testing reducer

```tsx
import { todosReducer as reducer, todosActions as actions } from './';
import {
todosReducer as reducer,
todosActions as actions,
TodosState,
} from './';

/**
* FIXTURES
*/
const activeTodo = { id: '1', completed: false, title: 'active todo' };
const completedTodo = { id: '2', completed: true, title: 'completed todo' };

const initialState = reducer(undefined, {} as any);
const getInitialState = (initial?: Partial<TodosState>) =>
reducer(initial as TodosState, {} as any);

/**
* STORIES
*/
describe('Todos Stories', () => {
describe('initial state', () => {
it('should match a snapshot', () => {
const initialState = getInitialState();
expect(initialState).toMatchSnapshot();
});
});

describe('adding todos', () => {
it('should add a new todo as the first element', () => {
const action = actions.add('new todo');
const state = reducer(initialState, action);
const initialState = getInitialState();
expect(initialState.todos).toHaveLength(0);
const state = reducer(initialState, actions.add('new todo'));
expect(state.todos).toHaveLength(1);
expect(state.todos[0].id).toEqual(action.payload.id);
expect(state.todos[0].title).toEqual('new todo');
});
});

describe('toggling completion state', () => {
it('should mark active todo as complete', () => {
const action = actions.toggle(activeTodo.id);
const state0 = { ...initialState, todos: [activeTodo] };
expect(state0.todos[0].completed).toBeFalsy();
const state1 = reducer(state0, action);
const activeTodo = { id: '1', completed: false, title: 'active todo' };
const initialState = getInitialState({ todos: [activeTodo] });
expect(initialState.todos[0].completed).toBeFalsy();
const state1 = reducer(initialState, actions.toggle(activeTodo.id));
expect(state1.todos[0].completed).toBeTruthy();
});
});
Expand Down Expand Up @@ -1595,6 +1600,18 @@ import Select from '@src/components/select';

[⇧ back to top](#table-of-contents)

### Imports in Module Decleration

> When creating 3rd party modules declarations all the imports should be put inside the module decleration, otherwise it will be treated as augmentation and show error
```ts
declare module "react-custom-scrollbars" {
import * as React from "react";

export interface positionValues {
...
```
[⇧ back to top](#table-of-contents)

### Type Augmentation for npm libraries
Strategies to fix issues coming from external type-definitions files (*.d.ts)

Expand Down
15 changes: 14 additions & 1 deletion README_SOURCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Issues can be funded by anyone and the money will be transparently distributed t
- [Recipes](#recipes)
- [Baseline tsconfig.json](#baseline-tsconfigjson)
- [Default and Named Module Exports](#default-and-named-module-exports)
- [Imports in Module Decleration](#imports-in-module-decleration)
- [Type Augmentation for npm libraries](#type-augmentation-for-npm-libraries)
- [Override type-definitions for npm libraries](#override-type-definitions-for-npm-libraries)
- [FAQ](#faq)
Expand Down Expand Up @@ -109,7 +110,7 @@ class MyComponent extends React.Component<Props, State> { ...
```

#### `React.ComponentProps<typeof Component>`
Gets type of Component Props, so you don't need to export Props from your component ever! (Works for both FC and Class components)
Gets component Props type. You don't no need to export Props from your component ever!
```tsx
type MyComponentProps = React.ComponentProps<typeof MyComponent>;
```
Expand Down Expand Up @@ -623,6 +624,18 @@ import Select from '@src/components/select';

[⇧ back to top](#table-of-contents)

### Imports in Module Decleration

> When creating 3rd party modules declarations all the imports should be put inside the module decleration, otherwise it will be treated as augmentation and show error
```ts
declare module "react-custom-scrollbars" {
import * as React from "react";

export interface positionValues {
...
```
[⇧ back to top](#table-of-contents)

### Type Augmentation for npm libraries
Strategies to fix issues coming from external type-definitions files (*.d.ts)

Expand Down

This file was deleted.

39 changes: 0 additions & 39 deletions playground/src/features/todos-typesafe/reducer.spec.ts

This file was deleted.

28 changes: 16 additions & 12 deletions playground/src/features/todos/reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
import { todosReducer as reducer, todosActions as actions } from './';
import {
todosReducer as reducer,
todosActions as actions,
TodosState,
} from './';

/**
* FIXTURES
*/
const activeTodo = { id: '1', completed: false, title: 'active todo' };
const completedTodo = { id: '2', completed: true, title: 'completed todo' };

const initialState = reducer(undefined, {} as any);
const getInitialState = (initial?: Partial<TodosState>) =>
reducer(initial as TodosState, {} as any);

/**
* STORIES
*/
describe('Todos Stories', () => {
describe('initial state', () => {
it('should match a snapshot', () => {
const initialState = getInitialState();
expect(initialState).toMatchSnapshot();
});
});

describe('adding todos', () => {
it('should add a new todo as the first element', () => {
const action = actions.add('new todo');
const state = reducer(initialState, action);
const initialState = getInitialState();
expect(initialState.todos).toHaveLength(0);
const state = reducer(initialState, actions.add('new todo'));
expect(state.todos).toHaveLength(1);
expect(state.todos[0].id).toEqual(action.payload.id);
expect(state.todos[0].title).toEqual('new todo');
});
});

describe('toggling completion state', () => {
it('should mark active todo as complete', () => {
const action = actions.toggle(activeTodo.id);
const state0 = { ...initialState, todos: [activeTodo] };
expect(state0.todos[0].completed).toBeFalsy();
const state1 = reducer(state0, action);
const activeTodo = { id: '1', completed: false, title: 'active todo' };
const initialState = getInitialState({ todos: [activeTodo] });
expect(initialState.todos[0].completed).toBeFalsy();
const state1 = reducer(initialState, actions.toggle(activeTodo.id));
expect(state1.todos[0].completed).toBeTruthy();
});
});
Expand Down