From 7be07c44fb11c028166d21f183726b9a4847adca Mon Sep 17 00:00:00 2001 From: Huw Wilkins Date: Tue, 27 Jul 2021 14:44:41 +1000 Subject: [PATCH] Add TypeScript config and emit errors when building TypeScript files. --- package.json | 3 ++- tsconfig.json | 27 +++++++++++++++++++++++++++ yarn.lock | 5 +++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tsconfig.json diff --git a/package.json b/package.json index c76b9b11050..81d55b24840 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "build": "yarn run build-css && yarn run build-js && yarn build-global-nav", "watch": "yarn run watch-css && yarn run watch-js", "watch-css": "watch -p 'static/sass/**/*.scss' -p 'node_modules/vanilla-framework/scss/**/*.scss' -c 'yarn run build-css'", - "watch-js": "watch -p 'static/js/src/**/*.js' -p 'static/js/src/**/*.jsx' -p 'static/js/data/**/*.js' -p 'static/js/third-party/**/*.js' -c 'yarn run build-js'", + "watch-js": "watch -p 'static/js/src/**/*.{js,jsx,ts,tsx}' -p 'static/js/data/**/*.js' -p 'static/js/third-party/**/*.js' -c 'yarn run build-js && tsc -noEmit'", "clean": "rm -rf node_modules yarn-error.log css static/css *.log *.sqlite _site/ build/ .jekyll-metadata .bundle static/js/dist etc/", "serve": "./entrypoint 0.0.0.0:${PORT}", "start": "yarn run build && concurrently --kill-others --raw 'yarn run watch-css' 'yarn run watch-js' 'yarn run serve'", @@ -81,6 +81,7 @@ "react-dom": "17.0.2", "react-query": "3.16.0", "smartquotes": "2.3.2", + "typescript": "4.3.5", "url-polyfill": "1.1.12", "url-search-params-polyfill": "8.1.0", "vanilla-framework": "2.32.0" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000000..db2038e7daa --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "allowJs": true, + "allowSyntheticDefaultImports": true, + "alwaysStrict": true, + "baseUrl": "static/js/src", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "jsx": "react-jsx", + "lib": ["dom", "dom.iterable", "esnext"], + "module": "esnext", + "moduleResolution": "node", + "noEmit": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "pretty": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "target": "es6", + "types": ["node", "jest"] + }, + "include": ["static/js/src"] +} diff --git a/yarn.lock b/yarn.lock index a06e663eae4..6f7233b4bcc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7638,6 +7638,11 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= +typescript@4.3.5: + version "4.3.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" + integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== + unbox-primitive@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471"