colors.js
colors.js copied to clipboard
shorter syntax not working in TypeScript
How can i achieve this syntax in my TS project
console.log('hello'.red)
<== instead of "hello", undefined is printed
me too
maybe you can try import 'colors' dont use import colors from 'colors' its solved my problem
I had the same problem and verifed @wrule 's solution works.
Doesn't work for me when targetting module 'ESNext' in TypeScript, I've tried both import 'colors'
and require('colors')
, but to no avail
UPDATE: fixed by setting moduleResolution
to "node" in tsconfig.json
I had the same issue, but the following did the trick:
import * as Color from 'colors';
// below line fixes color print
Color.red;
console.log('Oh my heavens! '.rainbow);