Skip to main content
← Gists
typescript Feb 19, 2026

Exact Object Types

Reject excess properties in object literals without runtime checks.

When you accept object literals, extra properties often sneak in. Exact makes those excess keys a type error.

Type

exact.ts
type Exact<T, Shape extends T> = T & Record<Exclude<keyof Shape, keyof T>, never>

type User = {
id: string
email: string
}

function acceptUser<T extends User>(user: Exact<User, T>) {
return user
}

acceptUser({ id: 'u1', email: 'a@b.com' })
// @ts-expect-error: excess property
acceptUser({ id: 'u1', email: 'a@b.com', admin: true })

This preserves autocomplete while enforcing strict shapes at the call site.