4

From DefinitelyTyped:

export type CSSProperties = & ObservableProperties & ObservableProperties;

Every description of ampersand that I can find says that it is an intersection operator. In which case, what does the first ampersand mean?

References:

Ed Staub
  • 15,480
  • 3
  • 61
  • 91

1 Answers1

8

Leading ampersand is ignored by the current version of the compiler, pretty much in the same way as the last ; is ignored inside interface declaration:

interface a {
    a(): string;
}


type b = & a;

TypeScript playground says type b = a

The typings linked from the question are (ab)using this feature to have more uniform syntax for intersection types:

export type CSSProperties =
    & ObservableProperties<csstype.Properties>
    & ObservableProperties<csstype.PropertiesHyphen>;

When written this way, when you remove the first intersection member for example, you can just delete the whole line and you don't have to change anything else.

artem
  • 46,476
  • 8
  • 74
  • 78