Skip to content

Instantly share code, notes, and snippets.

@magic-akari
Last active December 7, 2018 16:19
Show Gist options
  • Save magic-akari/aa10dfb809268eb4f63d5749d113a93a to your computer and use it in GitHub Desktop.
Save magic-akari/aa10dfb809268eb4f63d5749d113a93a to your computer and use it in GitHub Desktop.
tsc bug demo
export class App extends React.Component {
readonly state = { clicked: 0 };
onClick = () => this.setState({ clicked: this.state.clicked + 1 });
public render() {
return (
<div>
<div>You have clicked {this.state.clicked}</div>
<button onClick={this.onClick}>click me</button>
</div>
);
}
}
declare global {
const React: typeof import("react");
const ReactDOM: typeof import("react-dom");
}
export {};
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>demo</title>
</head>
<body>
<div class="app"></div>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/umd/react.production.min.js"
integrity="sha256-JBRLQT7aJ4mVO0H2HRhGghv/K76c5WzE57wW0Flc6ZY="
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/umd/react-dom.production.min.js"
integrity="sha256-r3C7TtdCy1+TrjcCfRt8JYhwjH3zaYHxHhvSBj8WfrE="
crossorigin="anonymous"
></script>
<script src="./index.js" type="module"></script>
</body>
</html>
import { App } from "./app.js";
ReactDOM.render(React.createElement(App, null), document.querySelector(".app"));
{
"name": "test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"scripts": {
"start": "tsc"
},
"devDependencies": {
"@types/react": "^16.7.10",
"@types/react-dom": "^16.0.11",
"typescript": "^3.2.1"
},
"dependencies": {
"react": "^16.6.3",
"react-dom": "^16.6.3"
}
}
{
"compilerOptions": {
"target": "es2018",
"module": "esnext",
"jsx": "react",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment