To illustrate what I'm looking for:
interface Thing {
id: string
name: string
amount: number
}
type OtherProps = string[] // What goes in here instead of `string[]`?
function processOtherProps(props: OtherProps) {
throw new Error("unimplemented")
}
processOtherProps(["someOtherProp"]) // Ok
processOtherProps(["name"]) // Compiler error because "name" is a key of Thing
processOtherProps(["someOtherProp", "amount"]) // Compiler error because "amount" is a key of Thing
How do I declare OtherProps in a way that produces the expected outputs in the last three lines?
processOtherPropsgeneric. On mobile now so if I don’t get to it I’m sure someone else will explain. Good luck!never? I tried this for a while but couldn't figure out myselfstringexceptkeyof Thing". Conditional types do not give you this. Had negated types as in ms/TS#29317 been implemented, you could have writtenstring & not keyof Thing. You can use generic types, but it would require something liketype OtherProps<K extends string> = Exclude<K, keyof Thing>[]and then you carryKaround everywhere, like this. If you want me to write that up as an answer, let me know (although the existing answer is similar)