Skip to content
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

Merged
merged 13 commits into from
Jul 16, 2020
Merged

Conversation

simonschneider-db
Copy link
Contributor

What type of PR is this? (check all applicable)

  • Other

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:

  • DashboardListEmptyState is ported over to TypeScript.
  • EmptyState has a .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:

image

…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)
const tsConfigPath = path.join(basePath, "tsconfig.json");

if (!fs.existsSync(tsConfigPath)) {
throw new Error(`Can not find tsconfig: ${tsConfigPath}`);
Copy link
Contributor Author

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.

"target": "es5",
"jsx": "react",
"allowJs": true
}
Copy link
Contributor

@benamorbe benamorbe Jul 9, 2020

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';

}
Copy link
Contributor

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
}
}
Copy link
Contributor

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:

Suggested change
}
"include": [
"app"
]
}

"module": "es6",
"target": "es5",
"jsx": "react",
"allowJs": true
Copy link
Contributor

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?

Suggested change
"allowJs": true
"allowJs": true,
"lib": [
"dom",
"dom.iterable",
"es6"
],

"target": "es5",
"jsx": "react",
"allowJs": true
}
Copy link
Contributor

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 :

  1. skipLibCheck: true: skips unnecessary lib checks in *.d.ts files (usually outside our scope)
  2. noEmit: true: We use webpack so we should avoid emitting any output accidentally when running tsc manually.
  3. strict: true: Enable strict type checking.
  4. forceConsistentCasingInFileNames: true: Disallow inconsistently-cased references to the same file.

…x default export of DashboardList and run prettier on eslintrc
Copy link
Member

@arikfr arikfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@arikfr arikfr merged commit 48924de into getredash:master Jul 16, 2020
@arikfr
Copy link
Member

arikfr commented Jul 16, 2020

Thanks!!

@ghost ghost mentioned this pull request Aug 30, 2020
1 task
andrewdever pushed a commit to andrewdever/redash that referenced this pull request Oct 5, 2020
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants