Skip to content

Type Alias: LooseRequired<TypeParameter>

LooseRequired<TypeParameter> = { [PropertyType in keyof (TypeParameter & Required<TypeParameter>)]: TypeParameter[PropertyType] }

Type utility that makes all properties required while preserving undefined values. Unlike Required<T>, this allows properties to be undefined but ensures they exist.

Type Parameters

TypeParameter

TypeParameter

The type to make loosely required

Example

typescript
interface User {
  name?: string
  age?: number | undefined
  email?: string
}

// All properties are required but can still be undefined
type LooseRequiredUser = LooseRequired<User>
// Result: { name: string | undefined; age: number | undefined; email: string | undefined }

const user: LooseRequiredUser = {
  name: undefined,    // OK - property exists but is undefined
  age: undefined,     // OK
  email: 'test@example.com' // OK
}

Released under the MIT License.