toml-node icon indicating copy to clipboard operation
toml-node copied to clipboard

✨ Improve type definition of `parse` function

Open micalevisk opened this issue 2 years ago • 1 comments

Now users can optionally supply the type of the parsed data like the following:

const myData = toml.parse<MyData>(myInput);
//        ^? MyData

instead of doing

const myData: MyData = toml.parse(myInput);

Notice that the default type is still any thus both approach above works.


As an workaround to this, I augmented toml with this ambient file:

toml.d.ts
declare module 'toml' {
  export function parse<TOutput = any>(input: string): TOutput;
}

micalevisk avatar Nov 21 '21 14:11 micalevisk

Hi @BinaryMuse! can you please review this one? it should be pretty straightforward :smiley:

micalevisk avatar Jan 14 '22 19:01 micalevisk