Created
November 24, 2020 18:43
-
-
Save dovidweisz/4d76168339db89cf05e1090a84b7ee41 to your computer and use it in GitHub Desktop.
Patch react-use types for Typescript 4
This file contains hidden or 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 fs = require("fs"); | |
const path = require("path"); | |
/** | |
* | |
* Patching react-use for Typescript 4.1 | |
* | |
* The latest version of typescript causes changs the name of a type used by react-use. | |
* | |
* https://github.com/streamich/react-use/issues/1646 | |
* | |
* Patching it until the issue is resolved. | |
*/ | |
const tsfilePath = path.resolve("node_modules", "react-use", "lib", "useGeolocation.d.ts"); | |
const testExpression = /([^n])PositionError/; | |
fs.readFile(tsfilePath, (err, content) => { | |
if (err) { | |
throw err; | |
} | |
const contentString = `${content}`; | |
if (testExpression.test(contentString)) { | |
console.log(`Patching ${tsfilePath} to be compatible with TypeScript 4.`); | |
const newContent = contentString.replace(testExpression, "$1GeolocationPositionError"); | |
fs.writeFile(tsfilePath, newContent, err => { | |
if (err) { | |
throw err; | |
} | |
console.log(`Sucessfully patched ${tsfilePath}`); | |
}); | |
} else { | |
console.log(`${tsfilePath} already patched.`); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment