From 80bb36b43d12f911d9ec667845ee5273833569ff Mon Sep 17 00:00:00 2001 From: brooketopcoder Date: Tue, 3 May 2022 12:01:38 -0700 Subject: [PATCH] PROD-1583 add support for typescript #time 10m --- package.json | 7 +- tsconfig.json | 34 +++++++++ tslint.json | 177 ++++++++++++++++++++++++++++++++++++++++++++++ webpack.config.js | 9 +++ 4 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 tsconfig.json create mode 100644 tslint.json diff --git a/package.json b/package.json index 627631e0..a81db598 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,16 @@ "@babel/plugin-transform-runtime": "^7.8.3", "@babel/preset-env": "^7.7.6", "@babel/preset-react": "^7.7.4", + "@babel/preset-typescript": "^7.16.7", "@babel/runtime": "^7.8.7", "@stripe/react-stripe-js": "1.3.0", "@stripe/stripe-js": "1.3.0", "@testing-library/jest-dom": "^5.5.0", "@testing-library/react": "^9.4.0", - "@types/jest": "^25.2.1", + "@types/jest": "^25.2.3", + "@types/node": "^17.0.23", + "@types/react": "^18.0.1", + "@types/react-dom": "^18.0.0", "@types/systemjs": "^6.1.0", "autoprefixer": "^9.8.6", "babel-eslint": "^11.0.0-beta.2", @@ -90,6 +94,7 @@ "redux-promise-middleware": "^6.1.2", "redux-thunk": "^2.3.0", "tc-auth-lib": "topcoder-platform/tc-auth-lib#1.0.4", + "typescript": "^4.6.3", "uuid": "^8.3.2" }, "browserslist": [ diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..6ed5a9dc --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,34 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "strictNullChecks": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "typeRoots": [ + "./types", + "./node_modules/@types" + ] + }, + "include": [ + "src" + ], + "exclude": [ + "**/*.test.*" + ] +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 00000000..29e1e39b --- /dev/null +++ b/tslint.json @@ -0,0 +1,177 @@ +{ + "extends": "tslint:latest", + "files": [], + "compilerOptions": { + "jsx": "react", + "declarationDir": "dist" + }, + "include": [ + "src/**/*" + ], + "exclude": [ + "src/**/*.test*" + ], + "rules": { + "array-type": [ + true, + "generic" + ], + "arrow-return-shorthand": true, + "callable-types": true, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "cyclomatic-complexity": [ + true, + 7 + ], + "deprecation": { + "severity": "none" + }, + "eofline": true, + "forin": true, + "import-blacklist": [ + true, + "rxjs/Rx" + ], + "import-spacing": true, + "indent": [ + true, + "spaces", + 4 + ], + "interface-over-type-literal": true, + "label-position": true, + "max-classes-per-file": [ + true, + 1 + ], + "max-line-length": false, + "member-access": false, + "member-ordering": [ + true, + { + "alphabetize": true, + "order": [ + "private-static-field", + "private-instance-field", + "private-static-accessor", + "private-instance-accessor", + "public-static-field", + "public-instance-field", + "public-static-accessor", + "public-instance-accessor", + "public-constructor", + "private-constructor", + "public-instance-method", + "private-instance-method" + ] + } + ], + "no-arg": true, + "no-bitwise": true, + "no-consecutive-blank-lines": true, + "no-console": true, + "no-construct": true, + "no-debugger": true, + "no-duplicate-super": true, + "no-empty": false, + "no-empty-interface": true, + "no-eval": true, + "no-implicit-dependencies": [ + true, + "dev" + ], + "no-inferrable-types": [ + false, + "ignore-params" + ], + "no-misused-new": true, + "no-null-keyword": true, + "no-non-null-assertion": true, + "no-shadowed-variable": true, + "no-string-literal": false, + "no-string-throw": true, + "no-submodule-imports": [ + true, + "@heroicons" + ], + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unnecessary-initializer": true, + "no-unused-expression": true, + "no-var-keyword": true, + "object-literal-sort-keys": true, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "ordered-imports": [ + true, + { + "grouped-imports": true + } + ], + "prefer-const": true, + "quotemark": [ + true, + "single" + ], + "radix": true, + "semicolon": [ + true, + "never" + ], + "trailing-comma": [ + true, + { + "multiline": { + "objects": "always", + "arrays": "always", + "typeLiterals": "ignore" + }, + "esSpecCompliant": true + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": [ + true, + "call-signature", + "parameter", + "property-declaration", + "variable-declaration", + "member-variable-declaration", + "object-destructuring", + "array-destructuring" + ], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "unified-signatures": true, + "variable-name": false, + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type" + ] + } +} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 3e51eed4..19147bb0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -86,6 +86,14 @@ module.exports = (webpackConfigEnv) => { outputPath: "icons", }, }, + { + test: /\.(js|jsx|ts|tsx)$/, + exclude: /(node_modules|bower_components)/, + loader: "babel-loader", + options: { + presets: ["@babel/env", "@babel/preset-react", "@babel/preset-typescript"] + } + }, ], }, resolve: { @@ -102,6 +110,7 @@ module.exports = (webpackConfigEnv) => { thunks: path.resolve(__dirname, "src/thunks"), hoc: path.resolve(__dirname, "src/hoc"), }, + extensions: [".ts", ".tsx", ".js", ".jsx"] }, plugins: [ new webpack.DefinePlugin({