Skip to content

Commit ae1b8a5

Browse files
zoltanbedimarkerikson
authored andcommitted
Create declaration files with typescript (#128)
* refactor(serializableStateInvariantMiddleware): named import instead of default * refactor(build): create types with typescript * fix(build): don't add interfaces to umd/esm modules
1 parent 6d1f04a commit ae1b8a5

10 files changed

+32
-63
lines changed

index.d.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"main": "dist/redux-starter-kit.cjs.js",
77
"module": "dist/redux-starter-kit.esm.js",
88
"unpkg": "dist/redux-starter-kit.umd.js",
9+
"types": "dist/typings.d.ts",
910
"author": "Mark Erikson <mark@isquaredsoftware.com>",
1011
"license": "MIT",
1112
"devDependencies": {
@@ -45,7 +46,6 @@
4546
},
4647
"files": [
4748
"dist",
48-
"index.d.ts",
4949
"src"
5050
],
5151
"dependencies": {

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default [
2020
plugins: [
2121
babel({
2222
extensions,
23-
exclude: 'node_modules/**'
23+
exclude
2424
}),
2525
resolve({
2626
extensions

src/configureStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from 'redux'
1515
import { composeWithDevTools } from 'redux-devtools-extension'
1616
import thunk, { ThunkDispatch, ThunkMiddleware } from 'redux-thunk'
17-
import createSerializableStateInvariantMiddleware from './serializableStateInvariantMiddleware'
17+
import { createSerializableStateInvariantMiddleware } from './serializableStateInvariantMiddleware'
1818

1919
import isPlainObject from './isPlainObject'
2020

src/index.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
1-
export { combineReducers, compose } from 'redux'
2-
export { default as createNextState } from 'immer'
3-
export { default as createSelector } from 'selectorator'
4-
5-
export { configureStore, getDefaultMiddleware } from './configureStore'
6-
export { createAction, getType } from './createAction'
7-
export { createReducer } from './createReducer'
8-
export { createSlice } from './createSlice'
9-
export {
10-
default as createSerializableStateInvariantMiddleware,
11-
isPlain
12-
} from './serializableStateInvariantMiddleware'
13-
14-
// Unfortunately, Babel's TypeScript plugin doesn't let us re-export
15-
// types using the `export { ... } from` syntax. Because it compiles
16-
// modules, independently, it has no way of knowing whether an identifier
17-
// refers to a type or value, and thus cannot strip the type re-exports
18-
// out of the generated JS.
19-
//
20-
// https://github.com/babel/babel/issues/8361
21-
//
22-
// As a workaround, the root of this repository contains an `index.d.ts`
23-
// that contains all type re-exports. Whenever adding a new public function
24-
// or type, remember to export it in `index.d.ts` as well.
1+
export * from './configureStore'
2+
export * from './createAction'
3+
export * from './createReducer'
4+
export * from './createSlice'
5+
export * from './serializableStateInvariantMiddleware'

src/serializableStateInvariantMiddleware.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Reducer } from 'redux'
22
import { configureStore } from './configureStore'
33

4-
import createSerializableStateInvariantMiddleware, {
4+
import {
5+
createSerializableStateInvariantMiddleware,
56
findNonSerializableValue
67
} from './serializableStateInvariantMiddleware'
78

src/serializableStateInvariantMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export interface SerializableStateInvariantMiddlewareOptions {
101101
*
102102
* @param options Middleware options.
103103
*/
104-
export default function createSerializableStateInvariantMiddleware(
104+
export function createSerializableStateInvariantMiddleware(
105105
options: SerializableStateInvariantMiddlewareOptions = {}
106106
): Middleware {
107107
const { isSerializable = isPlain } = options

src/typings.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export {
2+
Action,
3+
ActionCreator,
4+
AnyAction,
5+
Middleware,
6+
Reducer,
7+
Store,
8+
StoreEnhancer,
9+
combineReducers,
10+
compose
11+
} from 'redux'
12+
export { default as createNextState } from 'immer'
13+
export { default as createSelector } from 'selectorator'
14+
15+
export * from '.'

tsconfig.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{
22
"compilerOptions": {
33
"allowSyntheticDefaultImports": true,
4+
"emitDeclarationOnly": true,
45
"esModuleInterop": true,
6+
"declaration": true,
57
"module": "es2015",
68
"moduleResolution": "node",
7-
"noEmit": true,
89
"noUnusedLocals": true,
910
"noUnusedParameters": true,
11+
"outDir": "dist",
1012
"strict": true,
1113
"target": "es2018"
1214
},
13-
"include": ["src"]
15+
"include": ["src"],
16+
"exclude": ["src/*.test.ts"]
1417
}

type-tests/files/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"target": "es2018",
99
"baseUrl": "../..",
1010
"paths": {
11-
"redux-starter-kit": ["index.d.ts"]
11+
"redux-starter-kit": ["dist/typings.d.ts"]
1212
}
1313
}
1414
}

0 commit comments

Comments
 (0)