BinaryMuse / toml-node

TOML parser for Node.js and the Browser. Parses TOML v0.4.0
http://binarymuse.github.io/toml-node/
MIT License
306 stars 30 forks source link

✨ Add TypeScript definition #31

Closed marvinroger closed 7 years ago

marvinroger commented 7 years ago

This PR adds TypeScript types definition, allowing the module to be used from a TypeScript file.

It would be great if you could minor bump and publish this to npm after the PR is merged. Thanks!

BinaryMuse commented 7 years ago

Thanks, @marvinroger.

Curious, why the change in the return type from Object to any?

marvinroger commented 7 years ago

Sure: take a look at this example. You'll see the console.log(parsed.foo) is underlined in red, meaning it did not "pass" the static type checking. The reason is actually pretty simple: you can use the Object type only if you know in advance what properties the object will contain - like parameters of a method -. This is not our case, so we have to use any. See also Basic Types#any

BinaryMuse commented 7 years ago

@marvinroger Got it, thanks! (Not a TypeScript user if you couldn't tell :P)

BinaryMuse commented 7 years ago

Published as v2.3.1