3 ms·
'any' has always been intended as an escape hatch, so no abuse here [1]. The type representing the set of all possible values (the top type in the type lattice)
by remolueoend 2y ago
'any' has always been intended as an escape hatch, so no abuse here [1]. The type representing the set of all possible values (the top type in the type lattice) is 'unknown'.
[1] https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any https://www.typescriptlang.org/docs/handbook/2/everyday-type...
[2] https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type https://www.typescriptlang.org/docs/handbook/release-notes/t...
- epolanski 2y agounknown is not equivalent to any as a type constraint: doesn't work. https://www.totaltypescript.com/any-considered-harmful#type-argument-constraints https://www.totaltypescript.com/any-considered-harmful#type-...
- deleted 2y ago[deleted]
- matt_kantor 2y agoThe widest possible function type is `(...args: never) => unknown`. This is because parameters are contravariant, and `never` is the bottom type. Using that type works in the author's example[0]. I've got an issue open about TypeScript's provided `ReturnType` type which is somewhat related to this[1]. [0]: https://tsplay.dev/Wy0Ogm https://tsplay.dev/Wy0Ogm [1]: https://github.com/microsoft/TypeScript/issues/55667 https://github.com/microsoft/TypeScript/issues/55667