Message from JavaScript discussions

November 2020

— Do I always have to Pick<> then?

— 

So in this case, you can do something like:

{ readFile: (path: string, enc: string) => string & (path: string) => Buffer }

(which granted is quite a big signature, BUT it grants you the ability to provide only the API your function needs, and not the entire fs library)

— Another cool benefit is that if node stdlib has breaking changes, you can detect if your functions are affected by it, since TS will actually compare the structures

Message permanent page

— 🤔 okay

— Nice

— Pick is also fine, as long as you can construct a manageable substructure like the above

— But then you're depending directly on another type essentially

— So if you have a function that takes this type, passing fs to it is completely fine

— Aka: fs is "assignable" to that type

— Which doesn't mean that that type is "assignable" to the fs type

— So if you have a function that takes fs, you can't provide an implementation of only the above and also make the type system happy

Message permanent page

— TS does not differentiate between my self-constructed type signature, if it matches with the existing one?

Message permanent page