NoExcessProperties<T, U>Constrains a type to prevent excess properties not present in T.
When to use
Use to catch accidental extra properties in generic functions at compile time.
Details
Extra keys from U that are not in T are mapped to never.
Example (Preventing extra properties)
import type { Types } from "effect"
type Expected = { a: number; b: string }
type Input = { a: number; b: string; c: boolean }
type Result = Types.NoExcessProperties<Expected, Input>
// { a: number; b: string; readonly c: never }types
Source effect/Types.ts:8141 lines
export type type NoExcessProperties<T, U> = T &
Readonly<
Record<Exclude<keyof U, keyof T>, never>
>
Constrains a type to prevent excess properties not present in T.
When to use
Use to catch accidental extra properties in generic functions at compile time.
Details
Extra keys from U that are not in T are mapped to never.
Example (Preventing extra properties)
import type { Types } from "effect"
type Expected = { a: number; b: string }
type Input = { a: number; b: string; c: boolean }
type Result = Types.NoExcessProperties<Expected, Input>
// { a: number; b: string; readonly c: never }
NoExcessProperties<function (type parameter) T in type NoExcessProperties<T, U>T, function (type parameter) U in type NoExcessProperties<T, U>U> = function (type parameter) T in type NoExcessProperties<T, U>T & type Readonly<T> = {
readonly [P in keyof T]: T[P]
}
Make all properties in T readonly
Readonly<type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<keyof function (type parameter) U in type NoExcessProperties<T, U>U, keyof function (type parameter) T in type NoExcessProperties<T, U>T>, never>>Referenced by 1 symbols