-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Add TypeScript support #5027
Add TypeScript support #5027
Conversation
…ample components to typescript and add an example definition file.
…rror while parsing tsconfig.json, The 'files' list in config file 'tsconfig.json' is empty` See (TypeStrong/ts-loader#405 (comment))
…ker container (only webpack.config.js is copied over from root folder in Dockerfile)
webpack.config.js
Outdated
const tsConfigPath = path.join(basePath, "tsconfig.json"); | ||
|
||
if (!fs.existsSync(tsConfigPath)) { | ||
throw new Error(`Can not find tsconfig: ${tsConfigPath}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this line because the initial error I got for the missing tsConfig file in the docker container was missleading (see TypeStrong/ts-loader#405 (comment))
I then figured out that I either need to move tsconfig into /client
or copy it over in the Dockerfile.
client/tsconfig.json
Outdated
"target": "es5", | ||
"jsx": "react", | ||
"allowJs": true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about also adding allowSyntheticDefaultImports
to have similar imports as in js
files?
Without that option we have to import like this
import * as React from 'react';
With this option ON we can import AND destructure like this:
import React, { useState, useEffect, Component } from 'react';
client/jsconfig.json
Outdated
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think jsconfig.json
is ignored/skipped when a tsconfig.json
file exists too. Also having 2 files makes syncing difficult between both. In that case we can have both "allowJS": true
and "checkJS": true
in tsconfig.json
.
"jsx": "react", | ||
"allowJs": true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add explicit include
to avoid compiling non-source files? Something like:
} | |
"include": [ | |
"app" | |
] | |
} |
client/tsconfig.json
Outdated
"module": "es6", | ||
"target": "es5", | ||
"jsx": "react", | ||
"allowJs": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add DOM/ES libs?
"allowJs": true | |
"allowJs": true, | |
"lib": [ | |
"dom", | |
"dom.iterable", | |
"es6" | |
], |
client/tsconfig.json
Outdated
"target": "es5", | ||
"jsx": "react", | ||
"allowJs": true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other useful/recommended compiler options :
skipLibCheck: true
: skips unnecessary lib checks in*.d.ts
files (usually outside our scope)noEmit: true
: We usewebpack
so we should avoid emitting any output accidentally when runningtsc
manually.strict: true
: Enable strict type checking.forceConsistentCasingInFileNames: true
: Disallow inconsistently-cased references to the same file.
…een ES6/7 and typescript compilation.
…x default export of DashboardList and run prettier on eslintrc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thanks!! |
* 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
What type of PR is this? (check all applicable)
Description
Adds the typescript loader to webpack config and package.json, adds typescript specific linting to eslint and updates npm scripts in package.json to include
.ts
and.tsx
.I added two examples of using TypeScript:
.d.ts
companion file that adds type definition.Both examples show how we can move existing code over to TypeScript step by step.
Related Tickets & Documents
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
Dashboard stays the same: