Skip to content

Commit

Permalink
Create declaration files with typescript (reduxjs#128)
Browse files Browse the repository at this point in the history
* refactor(serializableStateInvariantMiddleware): named import instead of default

* refactor(build): create types with typescript

* fix(build): don't add interfaces to umd/esm modules
  • Loading branch information
zoltanbedi authored and markerikson committed Apr 28, 2019
1 parent 6d1f04a commit ae1b8a5
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 63 deletions.
31 changes: 0 additions & 31 deletions index.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"main": "dist/redux-starter-kit.cjs.js",
"module": "dist/redux-starter-kit.esm.js",
"unpkg": "dist/redux-starter-kit.umd.js",
"types": "dist/typings.d.ts",
"author": "Mark Erikson <[email protected]>",
"license": "MIT",
"devDependencies": {
Expand Down Expand Up @@ -45,7 +46,6 @@
},
"files": [
"dist",
"index.d.ts",
"src"
],
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default [
plugins: [
babel({
extensions,
exclude: 'node_modules/**'
exclude
}),
resolve({
extensions
Expand Down
2 changes: 1 addition & 1 deletion src/configureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension'
import thunk, { ThunkDispatch, ThunkMiddleware } from 'redux-thunk'
import createSerializableStateInvariantMiddleware from './serializableStateInvariantMiddleware'
import { createSerializableStateInvariantMiddleware } from './serializableStateInvariantMiddleware'

import isPlainObject from './isPlainObject'

Expand Down
29 changes: 5 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
export { combineReducers, compose } from 'redux'
export { default as createNextState } from 'immer'
export { default as createSelector } from 'selectorator'

export { configureStore, getDefaultMiddleware } from './configureStore'
export { createAction, getType } from './createAction'
export { createReducer } from './createReducer'
export { createSlice } from './createSlice'
export {
default as createSerializableStateInvariantMiddleware,
isPlain
} from './serializableStateInvariantMiddleware'

// Unfortunately, Babel's TypeScript plugin doesn't let us re-export
// types using the `export { ... } from` syntax. Because it compiles
// modules, independently, it has no way of knowing whether an identifier
// refers to a type or value, and thus cannot strip the type re-exports
// out of the generated JS.
//
// https://github.com/babel/babel/issues/8361
//
// As a workaround, the root of this repository contains an `index.d.ts`
// that contains all type re-exports. Whenever adding a new public function
// or type, remember to export it in `index.d.ts` as well.
export * from './configureStore'
export * from './createAction'
export * from './createReducer'
export * from './createSlice'
export * from './serializableStateInvariantMiddleware'
3 changes: 2 additions & 1 deletion src/serializableStateInvariantMiddleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Reducer } from 'redux'
import { configureStore } from './configureStore'

import createSerializableStateInvariantMiddleware, {
import {
createSerializableStateInvariantMiddleware,
findNonSerializableValue
} from './serializableStateInvariantMiddleware'

Expand Down
2 changes: 1 addition & 1 deletion src/serializableStateInvariantMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export interface SerializableStateInvariantMiddlewareOptions {
*
* @param options Middleware options.
*/
export default function createSerializableStateInvariantMiddleware(
export function createSerializableStateInvariantMiddleware(
options: SerializableStateInvariantMiddlewareOptions = {}
): Middleware {
const { isSerializable = isPlain } = options
Expand Down
15 changes: 15 additions & 0 deletions src/typings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export {
Action,
ActionCreator,
AnyAction,
Middleware,
Reducer,
Store,
StoreEnhancer,
combineReducers,
compose
} from 'redux'
export { default as createNextState } from 'immer'
export { default as createSelector } from 'selectorator'

export * from '.'
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"emitDeclarationOnly": true,
"esModuleInterop": true,
"declaration": true,
"module": "es2015",
"moduleResolution": "node",
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "dist",
"strict": true,
"target": "es2018"
},
"include": ["src"]
"include": ["src"],
"exclude": ["src/*.test.ts"]
}
2 changes: 1 addition & 1 deletion type-tests/files/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"target": "es2018",
"baseUrl": "../..",
"paths": {
"redux-starter-kit": ["index.d.ts"]
"redux-starter-kit": ["dist/typings.d.ts"]
}
}
}

0 comments on commit ae1b8a5

Please sign in to comment.