#How to create an object type which restrict its fields based on another object type?

4 messages · Page 1 of 1 (latest)

round owl
#

If I have:

type A = {
  cancel: number
}

type B = {
  [k: string]: number
}

I want a type that is like type B (string => number) but can't have the properties of type A

heavy shard
#

negated types aren't a thing in typescript, so there's no way to represent a value that can't have some specific property

#

there is a way to force such a check when assigning an object literal (using { property?: never }), but that's not actually a guarantee that the object doesn't have that property at runtime

round owl
#

I did it at the function type level. Thanks!