Skip to content

Create declaration files with typescript #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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"]
}
}
}