Could not find a declaration file for module 'buffer-layout'
carnesen opened this issue · comments
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.
@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.
@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.