developit/dlv

types (TypeScript)

chodorowicz opened this issue ยท 7 comments

Hey! ๐Ÿ‘‹

Thanks for this little gem ๐Ÿ’Ž

I'm wondering are you open to committing TS type declaration to the repo? Or should I add them to DefinitelyTyped repo?

I'd be happy to have them here! It's probably quite a difficult definition to write since the keypath argument is so opaque though.

Yeah, I agree, I'm not even sure if that's possible. What do you think about adding something basic, so at least we know how many and what arguments dlv function takes. We can use also new unknown type so it we'd be forced to cast result. I'm using sth like this currently:

declare module "dlv" {
  type Dlv = <T>(obj: object, key: string | string[], defaultValue?: T) => unknown | T;
  const dlv: Dlv;
  export = dlv;
}

I've just found a comment by Daniel Rossenwasser that preferable way for non TS libraries is to add types to DefinitelyTyped. I will try to do that!

PR created in DefinitelyTyped. I avoided using the unknown type since I'm currently using TS 2.8 and the unknown type is a 3.0 feature
DefinitelyTyped/DefinitelyTyped#32536

Cool ๐Ÿ‘

@developit , you can close this issue now

thanks all!