- Replaces the hardcoded `unknown` type in for example `is.promise(value)` with `is.promise<T>(value)` so that a known (inferred or explicit) generic type `T` can be propagated in the type system.
- The same goes for `Key` and `Value` types in for example `Map<Key, Value>`, and so on.
- Also replacing `{[key: string]: unknown}` and similar with
`Record<Key, Value>` as appropriate.
- Kept `is.plainObject` as Record<string, Value>`, although the
`Key` can also be a `symbol`.
- If no inferred/explicit generic type is provided, the (current) default/implicit generic type is preserved. It is usually `unknown`.
- Use with caution, as `is` (nor the associated assertions) can not check generic type validity at runtime. It is a compile-time check performed by typescript, based on the developer-provided types (inferred or implicit).
- Making the wrong compile-time assumption about `T` can result in value with types which differ at runtime, leading to unexpected behavior. It is safer to stick with `unknown` generic types until they have been verified at runtime. This is particularly important when it comes to verifying the types of arbitrary inputs from users and external systems.
See
- https://www.typescriptlang.org/docs/handbook/generics.html
- https://github.com/sindresorhus/is/issues/102