I am trying to create an interface / a type definition, which when used in union types, prohibits a certain key in a child of the interface (here, I want to find the correct definition for Abc
):
type Abc = {
someField: {
prohibited?: never,
},
};
type UsedHere = {someField: {anotherField: string}} & Abc;
I have tried the types never
, undefined
and void
for prohibited
, with and without the ?
, but typescript always tells me that I need a value for prohibited
when I create a variable of type UsedHere
. How can I tell typescript that this value in fact cannot exist? An example for an object which should be valid is:
let x: UsedHere = {
someField: {
anotherField: ""
}
}
EDIT: this problem only occurs in typescript versions prior to 3.6