I am using chalk with a JavaScript project that I'm checking with TypeScript's checkJs flag.
The JavaScript code imports it like so:
const chalk = require('chalk')
Unfortunately, chalk ships its own types, and its types are wrong. It should use the syntax export = chalk (which is TypeScript's syntax for CommonJS) but instead does export default chalk.
Somebody submitted a PR to fix it, but the project hasn't merged any PRs in a while.
How can I work around the bad export from the chalk typings?
You can override the package's types by providing a path mapping:
chalk-override.d.ts in your project root. Copy the chalk types in there and fix them.Add the following to your tsconfig.json (create one with tsc --init --checkJs if you haven't already):
{
// ... other settings ...
"baseUrl": "./",
"paths": {
"chalk": ["chalk-override"]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With