jkroso / parse-duration

convert a human readable duration to ms
MIT License
243 stars 37 forks source link

Typescript support for adding more units #37

Closed piotr-musialek-skyrise closed 3 years ago

piotr-musialek-skyrise commented 3 years ago

Unfortunately current type definition is only for the function. There is no way to add more units cause there is no index signature defined and parse['anything'] = generates error.

.d.ts file should have something like this instead:

declare const parse: ((input: string, format?: Units) => number) & {
  [key: string]: number | null;
};

export default parse;

I used the above to overwrite the type and it works fine for me.

dy commented 3 years ago

Would you mind making a PR? I'm not good at TS at all, I only know //@ts-ignore.