While reviewing code in a library, I came across the line unknown extends CustomTypes[K]
. My understanding is that this is a deferred type where unknown can always be assigned to CustomTypes[K]. However, I am unsure how this type is utilized and in what scenario it could result in false. Examples would greatly aid my comprehension.
/**
* Extendable Custom Types Interface
*/
type ExtendableTypes =
| 'Editor'
| 'Element'
| 'Text'
export interface CustomTypes {
[key: string]: unknown
}
export type ExtendedType<
K extends ExtendableTypes,
B
> = unknown extends CustomTypes[K] ? B : CustomTypes[K]