How to define TypeScript types for chalk's tagged template literal?

397 Views Asked by At

In chalk 2.0, it's possible to use tagged strings:

const chalk = require('chalk');
console.log(chalk`{bold some} text`);

How to amend chalk's type definitions to make TypeScript happy with it? Currently, I get:

error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'typeof Chalk' has no compatible call signatures.

1

There are 1 best solutions below

0
On

With Typescript, you should be using the import syntax vs require, and the error will go away.

import chalk from 'chalk';

Note that at the time you posted your question, there was also a template issue, but it has been fixed since.