colors.js icon indicating copy to clipboard operation
colors.js copied to clipboard

shorter syntax not working in TypeScript

Open ohabash opened this issue 4 years ago • 6 comments

How can i achieve this syntax in my TS project

console.log('hello'.red) <== instead of "hello", undefined is printed

ohabash avatar Oct 10 '19 19:10 ohabash

me too

wrule avatar Nov 11 '19 09:11 wrule

maybe you can try import 'colors' dont use import colors from 'colors' its solved my problem

wrule avatar Nov 11 '19 09:11 wrule

I had the same problem and verifed @wrule 's solution works.

mikemklee avatar Mar 21 '20 03:03 mikemklee

Doesn't work for me when targetting module 'ESNext' in TypeScript, I've tried both import 'colors' and require('colors'), but to no avail

kerberjg avatar May 07 '21 10:05 kerberjg

UPDATE: fixed by setting moduleResolution to "node" in tsconfig.json

kerberjg avatar May 07 '21 10:05 kerberjg

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);

enwi avatar Oct 20 '21 14:10 enwi