Defining the inverse of Partial in TypeScript

Mapped types are not all created equal. Homomorphic mapped types preserve modifiers of the mapped type. From the pull request introducing this feature:

With this PR we preserve property modifiers in homomorphic (structure preserving) mapped types. A mapped type of the form { [P in keyof T]: X } is homomorphic with T (because it has the same set of properties as T) and now preserves the optional and readonly modifiers as they exist on the properties in T.

Starting from 2.8 you can remove modifiers from such types using a - (see PR) :

type Full<T> = {
  [P in keyof T]-?: T[P];
}

Note

You can use the predefined Required type from the standard library which does the exact same thing as Full.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)