This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Project } = require("ts-morph"); | |
/** | |
* Loops through all TSX files and removes unused imports, | |
* which will cleanup the `import React from "react"` if it's no longer needed | |
*/ | |
const project = new Project({ | |
tsConfigFilePath: "tsconfig.json", | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type LoadState<T> = | |
| { state: "loading" } | |
| { state: "loaded", data: T } | |
// Not all usecases will have an error state, in which case it's fine to omit it here. | |
| { state: "error", err: string }; | |
type ExamplePayload = string; | |
const ExampleComponent = () => { | |
const [ loadState, setLoadState ] = useState<LoadState<ExamplePayload>>({ state: "loading" }); | |
useEffect(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Dispatch, useReducer, useEffect } from "react"; | |
import { produce } from "immer"; | |
//======= | |
// State | |
//======= | |
export type ExampleState = { | |
name: string; | |
level: number; | |
saved: false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import c from "./c"; | |
export default "a" + c; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import v1 from "./v1" | |
import v2 from "./v2" | |
import express from "express"; | |
var app = express(); | |
app.use("/v1", v1); | |
app.use("/v2", v2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Expected output: A B C (see http://www.es6fiddle.net/ice1qchm/) | |
//Actual output from Babel: A C | |
//ES5 legacy code | |
function A () { | |
console.log("A"); | |
} | |
function B () { |