Marak / colors.js

get colors in your node.js console
https://github.com/Marak/colors.js
Other
5.17k stars 446 forks source link

bold causing problems #168

Closed nevster closed 6 years ago

nevster commented 8 years ago

Hi Marak,

There's currently a problem as referenced here: https://github.com/Marak/colors.js/issues/110

When using colors in TypeScript, we get the following error: typings/globals/colors/index.d.ts(109,5): error TS2300: Duplicate identifier 'bold'

Is it possible for you to implement a workaround or at least update the typings here?: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/colors

Thanks

Marak commented 8 years ago

Will accept pull request

DABH commented 6 years ago

Can you confirm whether or not this is still an issue with the typings? Otherwise I will investigate at some point, I'm interested in full TS compliance and moving the typings out of DT to this repo.

alexandrebours commented 6 years ago

There is still an issue on my side: node_modules/@types/colors/index.d.ts(118,9): error TS2717: Subsequent property declarations must have the same type. Property 'bold' must be of type '() => string', but here has type 'string'.

DABH commented 6 years ago

Yeah, I’ve since read more — the issue is that ES6 has “bold()” as a String prototype — however, that is deprecated. So at some point these typings should be correct again :) but in the meantime we can see what an elegant fix is...

DABH commented 6 years ago

I couldn't seem to repro as I was messing around trying to solve this. Can someone (@alexandrebours ?) provide a MWE that triggers the TS2717, so I can investigate as well?

Moreover, very open to any ideas/workarounds...

DABH commented 6 years ago

Is it sufficient to ignore the error?? http://www.typescriptlang.org/play/#src=declare%20module%20%27foo%27%20%7B%0A%09global%20%7B%0A%09%09interface%20String%20%7B%0A%09%09%09%2F%2F%20%40ts-ignore%0A%09%09%09bold%3A%20string%3B%0A%09%09%7D%0A%09%7D%0A%7D%3B%0A%0Alet%20x%3Aany%20%3D%20%27bob%27.bold%3B That seems to avoid errors (without the ignore I can indeed repro now, woo hoo).

But even though this silences the error, does colors' bold work from Typescript now? If so, let's make this the official solution... lmk...

DABH commented 6 years ago

(Actually, I only have this silly browser example, without importing colors... if someone can provide a full .ts file and some tsc command that reproduces this, I'd be grateful!)

DABH commented 6 years ago

MWE provided thanks to @Dante-101 ... I’ll try applying my tentative fix to it soon-ish unless someone beats me to it. Note we should test against master branch of colors which now has the built-in typings and al the other 1.2.0 fixes

SlurpTheo commented 6 years ago

FYI: https://stackoverflow.com/questions/48640203/subsequent-property-declarations-must-have-the-same-type-property-string-should

Dante-101 commented 6 years ago

@SlurpTheo We need to make it work with targets newer than ES2015. A lot of us use esnext with Babel to write TS in latest syntax. It will be great if we can make this MWE work.

https://github.com/Dante-101/colors-ts-def-mwe

DABH commented 6 years ago

So seems like my ignore trick works lol. Thanks again for the MWE. I'm going to push my "fix," and then mark this closed. But, if anyone ever has a more elegant fix, or if bold is finally removed from ES, someone please re-open or make a new issue.