1
interface NumericalityGreaterOptions {
  greaterThan?: number;
  greaterThanOrEqualTo?: number;
}

interface NumericalityEqualOptions {
  equalTo?: number;
}

const x: NumericalityEqualOptions | NumericalityGreaterOptions = {
  greaterThanOrEqualTo: 4,
  equalTo: 3
};

https://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgHIFcC21gLgG2DAE8BxKCOSKAeQAcxgB7EAZ2QG8BYAKGWQDmFKtAAqACzggA-AC5kILACNoAbl78hlahKk0oAUQCO6AqKZyFytbwC+vXqGrwkaLDjyESx0-nqMWdm4+ZAgTMwt5RUwVKHUeex5eBECwZAAPeQxsKFwCImIfAn9mNmQAHzccvK8yYWoSwOQAXk4NQXqxSRB9IvxzeQAWABp2sN8B5ABmO1UgA I would however expect typescript to not allow x to have equalTo and greaterThanOrEqualTo as attributes as they are from different interfaces which are combined via a union type. I would expect this behaviour from:

NumericalityEqualOptions & NumericalityGreaterOptions

instead.

Am I doing something wrong or is this a bug?

Maurice Döpke
  • 367
  • 3
  • 9

0 Answers0