IsMappableObjectType TypeAlias
Detect if a type is a simple structural object.
For more information about our API support guarantees, see here.
Signature
export type IsMappableObjectType<T, True = true, False = false, Mapped = {
[P in keyof T]: T[P];
}> = [Mapped] extends [T] ? ([T] extends [Mapped] ? True : False) : False;
Type Parameters
| Parameter | Default | Description |
|---|---|---|
| T | ||
| True | true | |
| False | false | |
| Mapped | { [P in keyof T]: T[P]; } |
Remarks
This returns the true case if the type is entirely defined by its set of public properties. More concretely, this indicates if creating a mapped type based on T will be lossy due to details mapped types cannot access.
This is shallow, and distributes over unions.
This also returns the true case for primitive types since mapping over them leaves them unchanged if doing so in a generic context: Mapping over a primitive does not leave them unchanged if done directly (not to a generic type parameter), but this can not detect that behavior. This is fine as the use for this is to detect when making a mapped type from a generic type parameter would be lossy.