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

Could not find a declaration file for module 'buffer-layout' #77

Open
carnesen opened this issue Mar 30, 2022 · 2 comments
Open

Could not find a declaration file for module 'buffer-layout' #77

carnesen opened this issue Mar 30, 2022 · 2 comments

Comments

@carnesen
Copy link

The buffer-layout package does not provide types nor does it have types available as @types/buffer-layout in the DefinitelyTyped project. This results in a compilation error when using @blockworks-foundation/mango-client in a TypeScript project with strict compiler settings:

Could not find a declaration file for module 'buffer-layout'. '<my project path>/node_modules/buffer-layout/lib/Layout.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/buffer-layout` if it exists or add a new declaration (.d.ts) file containing `declare module 'buffer-layout';`

import { Blob, Layout, Structure, UInt, Union } from 'buffer-layout';

Adding a declaration declare module 'buffer-layout' like the error suggests leads to other difficult-to-diagnose type errors.

Thankfully the folks over at Solana Labs have created their own well-typed fork of buffer-layout and are rolling it out into their own published packages.

Could this library switch to using that fork too?

A temporary workaround that worked for me is suggested here: set "noImplicitAny": false in tsconfig.json.

@0xCryptoSheik
Copy link

@carnesen I'm using a ts declaration file, picked & adapted from a Solana repository: https://gist.github.com/0xCryptoSheik/4e333ad477a2119ef070e67cdfb673a3

I agree it would be best for Mango packages to start using @solana/buffer-layout too, as more & more packages of the ecosystem start using it, which results in duplicates for consumers, of essentially identical packages.

@carnesen carnesen changed the title Use @solana/buffer-layout instead of regular buffer-layout Could not find a declaration file for module 'buffer-layout' Apr 16, 2022
@carnesen
Copy link
Author

@0xCryptoSheik Thank you, we've incorporated your buffer-layout module definition into our project. This project could think about solving the issue that way too, by shipping your typedef (or similar) with this package. That would be less risky in the sense that it's guaranteed not to change the runtime behavior. I've updated the description of this issue to focus on the problem.

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

No branches or pull requests

2 participants