Skip to content

Commit ffe12d7

Browse files
simonschneider-dbandrewdever
authored andcommitted
Add TypeScript support (getredash#5027)
* TASK Add typescript dependencies to package.json * TASK Add typescript to build process and npm scripts and TASK Move example components to typescript and add an example definition file. * TASK Move back to ts-loader instead of babel typescript preset * FIX Remove unnecessary changes * FIX Explicitly mention tsconfig file in webpack.config.js to avoid `error while parsing tsconfig.json, The 'files' list in config file 'tsconfig.json' is empty` See (TypeStrong/ts-loader#405 (comment)) * FIX Move tsconfig to client subdirectory to make it accessible in docker container (only webpack.config.js is copied over from root folder in Dockerfile) * TASK Move from ts-loader to babel to reduce compatibility issues between ES6/7 and typescript compilation. * TASK Add types for classnames, hoist-non-react-statics and lodash. Fix default export of DashboardList and run prettier on eslintrc * Run npm install * Trigger tests * Run npm install 2 * Trigger tests
1 parent 02f442d commit ffe12d7

File tree

9 files changed

+2911
-510
lines changed

9 files changed

+2911
-510
lines changed

client/.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
],
88
"useBuiltIns": "usage"
99
}],
10-
"@babel/preset-react"
10+
"@babel/preset-react",
11+
"@babel/preset-typescript"
1112
],
1213
"plugins": [
1314
"@babel/plugin-proposal-class-properties",

client/.eslintrc.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
module.exports = {
22
root: true,
3-
extends: ["react-app", "plugin:compat/recommended", "prettier"],
4-
plugins: ["jest", "compat", "no-only-tests"],
3+
parser: "@typescript-eslint/parser",
4+
extends: [
5+
"react-app",
6+
"plugin:compat/recommended",
7+
"prettier",
8+
// Remove any typescript-eslint rules that would conflict with prettier
9+
"prettier/@typescript-eslint",
10+
],
11+
plugins: ["jest", "compat", "no-only-tests", "@typescript-eslint"],
512
settings: {
6-
"import/resolver": "webpack"
13+
"import/resolver": "webpack",
714
},
815
env: {
916
browser: true,
10-
node: true
17+
node: true,
1118
},
1219
rules: {
1320
// allow debugger during development
1421
"no-debugger": process.env.NODE_ENV === "production" ? 2 : 0,
1522
"jsx-a11y/anchor-is-valid": "off",
16-
}
23+
},
24+
overrides: [
25+
{
26+
// Only run typescript-eslint on TS files
27+
files: ["*.ts", "*.tsx", ".*.ts", ".*.tsx"],
28+
extends: ["plugin:@typescript-eslint/recommended"],
29+
rules: {
30+
// Do not require functions (especially react components) to have explicit returns
31+
"@typescript-eslint/explicit-function-return-type": "off",
32+
// Do not require to type every import from a JS file to speed up development
33+
"@typescript-eslint/no-explicit-any": "off",
34+
// Do not complain about useless contructors in declaration files
35+
"no-useless-constructor": "off",
36+
"@typescript-eslint/no-useless-constructor": "error",
37+
},
38+
},
39+
],
1740
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from "react";
2+
3+
export interface EmptyStateProps {
4+
header?: string;
5+
icon?: string;
6+
description: string;
7+
illustration: string;
8+
helpLink: string;
9+
10+
onboardingMode?: boolean;
11+
showAlertStep?: boolean;
12+
showDashboardStep?: boolean;
13+
showInviteStep?: boolean;
14+
}
15+
16+
declare const EmptyState: React.FunctionComponent<EmptyStateProps>;
17+
18+
export default EmptyState;

client/app/pages/dashboards/components/DashboardListEmptyState.jsx renamed to client/app/pages/dashboards/components/DashboardListEmptyState.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import React from "react";
2-
import PropTypes from "prop-types";
1+
import * as React from "react";
2+
import * as PropTypes from "prop-types";
33
import BigMessage from "@/components/BigMessage";
44
import NoTaggedObjectsFound from "@/components/NoTaggedObjectsFound";
55
import EmptyState from "@/components/empty-state/EmptyState";
66

7-
export default function DashboardListEmptyState({ page, searchTerm, selectedTags }) {
7+
export interface DashboardListEmptyStateProps {
8+
page: string;
9+
searchTerm: string;
10+
selectedTags: string[];
11+
}
12+
13+
export default function DashboardListEmptyState({ page, searchTerm, selectedTags }: DashboardListEmptyStateProps) {
814
if (searchTerm !== "") {
915
return <BigMessage message="Sorry, we couldn't find anything." icon="fa-search" />;
1016
}
@@ -30,5 +36,5 @@ export default function DashboardListEmptyState({ page, searchTerm, selectedTags
3036
DashboardListEmptyState.propTypes = {
3137
page: PropTypes.string.isRequired,
3238
searchTerm: PropTypes.string.isRequired,
33-
selectedTags: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types
39+
selectedTags: PropTypes.array.isRequired,
3440
};

client/jsconfig.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

client/tsconfig.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"compilerOptions": {
3+
// Target latest version of ECMAScript.
4+
"target": "esnext",
5+
// Search under node_modules for non-relative imports.
6+
"moduleResolution": "node",
7+
// Process & infer types from .js files.
8+
"allowJs": true,
9+
// Don't emit; allow Babel to transform files.
10+
"noEmit": true,
11+
// Enable strictest settings like strictNullChecks & noImplicitAny.
12+
"strict": true,
13+
// Import non-ES modules as default imports.
14+
"esModuleInterop": true,
15+
"jsx": "react",
16+
"allowSyntheticDefaultImports": true,
17+
"noUnusedLocals": true,
18+
"lib": [
19+
"dom",
20+
"dom.iterable",
21+
"esnext"
22+
],
23+
"forceConsistentCasingInFileNames": true,
24+
"baseUrl": "./",
25+
"paths": {
26+
"@/*": ["./app/*"]
27+
}
28+
},
29+
"include": [
30+
"app/**/*"
31+
],
32+
"exclude": [
33+
"dist"
34+
]
35+
}

0 commit comments

Comments
 (0)