diff --git a/package.json b/package.json index fde3f715..2a37e5ce 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "main": "dist/Shepherd.js", "module": "dist/Shepherd.es.js", "jsnext:main": "dist/Shepherd.es.js", + "types": "dist/index.d.ts", "homepage": "https://shipshapecode.github.io/react-shepherd/", "engines": { "node": ">=8", @@ -15,6 +16,7 @@ "scripts": { "test": "cross-env CI=1 react-scripts test", "test:watch": "react-scripts test", + "prebuild": "tsc --project ./tsconfig-declarations.json", "build": "rollup -c", "start": "rollup -c -w", "prepare": "yarn run build", diff --git a/src/index.tsx b/src/index.tsx index 2310b139..d081d0cc 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -34,7 +34,9 @@ const addSteps = (steps: Array | Array, tour: Tour) => { step.buttons = buttons.map((button: ShepherdStepWithType) => { const { type, classes, text, action } = button; return { - action: action || tour[type], + // TypeScript doesn't have great support for dynamic method calls with + // bracket notation, so we use the `any` escape hatch + action: action || (tour as any)[type!], classes, text, type diff --git a/tsconfig-declarations.json b/tsconfig-declarations.json new file mode 100644 index 00000000..e44e7d53 --- /dev/null +++ b/tsconfig-declarations.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "isolatedModules": false, + "noEmit": false, + "declaration": true, + "emitDeclarationOnly": true + } +}