Closed hamishfagg closed 1 year ago
Just help me understand this a bit better @hamishfagg, as I don't have a lot of TS experience. Bit of a broader chat about converting CO2.js to TS in #77.
I'm under the impression that TS handles JS natively, but I understand that having this would help folks using CO2.js in TS projects with compilation and type-checking in their IDE. Is that right?
It would also mean that this file needs to be included when the library is packaged for NPM, right?
I have very little TS experience as well so maybe someone can chime in who knows.
But basically without this file TS complains that it doesn't know what the co2
module is. With it, I'm able to import and use co2 normally.
It would also mean that this file needs to be included when the library is packaged for NPM, right?
Correct
Currently, TypeScript users get an error or a warning, that co2.js lacks typescript type definitions. You don't have to convert the library to TypeScript to fix this, you can just make a .d.ts
file and define the types there. Otherwise, I'd recommend upgrading the library to TypeScript, simply out of fact, that the majority people in WebDev are using TS and expect everything to work with TS
@mishushakov thanks for the extra context. I've merged this in, as a first step towards making the library more TS friendly. It's just enough TS.
We'd be open to a PR add more types for the hosting & data modules, or add other .d.ts
files. I might be up for a TS refactor (and to learn TS myself) later in the year, but for now we have a few higher priority features we'd like to introduce.
Adding this module declaration means that importing co2 from typescript is possible with:
import { co2 } from '@tgwf/co2'