Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript types for @squoosh/lib #1077

Closed
jrmyio opened this issue Jun 26, 2021 · 7 comments · Fixed by #1142
Closed

Typescript types for @squoosh/lib #1077

jrmyio opened this issue Jun 26, 2021 · 7 comments · Fixed by #1142
Labels
CLI CLI related issue

Comments

@jrmyio
Copy link

jrmyio commented Jun 26, 2021

I am trying to use Typescript to use @squoosh/lib but getting the usual error when no types are available:

Could not find a declaration file for module '@squoosh/lib'. '/test/squoosh/node_modules/@squoosh/lib/build/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/squoosh__lib` if it exists or add a new declaration (.d.ts) file containing `declare module '@squoosh/lib';`ts(7016)

Are there are no types included for this library or could I doing something wrong?

Currently using

// @ts-ignore
import { ImagePool } from '@squoosh/lib';

as a workaround.

@surma
Copy link
Collaborator

surma commented Jun 26, 2021

Yeah, we don’t have full types for libSquoosh yet, only for some of the files. It’s an incremental migration that @ergunsh is working on :)

@kosamari kosamari added the CLI CLI related issue label Jul 1, 2021
@hyoretsu
Copy link

hyoretsu commented Jul 18, 2021

Bump, trying to use this to replace imagemin with TypeScript, but it doesn't have types so I can't even IntelliSense what options/properties are available.

@surma
Copy link
Collaborator

surma commented Jul 18, 2021

That’s more a question of documentation than TypeScript tbh. Feel free to take a look at the options object in codecs.ts.

@hyoretsu
Copy link

Having a list of properties/arguments (that work with IntelliSense) and their types is sorta documention, but also one of the purposes of TS. Some even go as far as adding a description to everything, making it even more like a built-in documentation.

Linking to that specific object does help way more than what's currently in the docs though.

@surma
Copy link
Collaborator

surma commented Jul 19, 2021

Yeah, we know documentation is a weak point and we are working on that. Fwiw, we do link to codecs.ts from the README of libsquoosh.

@styfle
Copy link
Contributor

styfle commented Aug 20, 2021

@ergunsh Thoughts on this one?

I think we can do something like tsc --declaration --emitDeclarationOnly --declarationDir build to generate the .d.ts files and publish those to npm.

@ergunsh
Copy link
Contributor

ergunsh commented Sep 3, 2021

Totally @styfle! :)

I was a bit skeptical to expose the types before improving the type definitions for preprocess and encode functions since those take some complicated parameters and providing ts types without them felt a bit meaningless.

So, I created a PR to add the parameter types to those #1141 and created another PR to expose the types #1142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI CLI related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants