23.06.2015 Views

TypeScript Language Specification v1.5

TypeScript Language Specification v1.5

TypeScript Language Specification v1.5

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

o<br />

o<br />

If each type in U has an apparent string index signature, U has a string index signature of<br />

a union type of the types of the apparent string index signatures from each type in U.<br />

If each type in U has an apparent numeric index signature, U has a numeric index<br />

signature of a union type of the types of the apparent numeric index signatures from<br />

each type in U.<br />

If a type is not one of the above, it is considered to have no apparent members.<br />

In effect, a type's apparent members make it a subtype of the 'Object' or 'Function' interface unless the<br />

type defines members that are incompatible with those of the 'Object' or 'Function' interface—which, for<br />

example, occurs if the type defines a property with the same name as a property in the 'Object' or<br />

'Function' interface but with a type that isn't a subtype of that in the 'Object' or 'Function' interface.<br />

Some examples:<br />

var o: Object = { x: 10, y: 20 };<br />

var f: Function = (x: number) => x * x;<br />

var err: Object = { toString: 0 };<br />

// Ok<br />

// Ok<br />

// Error<br />

The last assignment is an error because the object literal has a 'toString' method that isn't compatible with<br />

that of 'Object'.<br />

3.10.2 Type and Member Identity<br />

Two types are considered identical when<br />

<br />

<br />

<br />

<br />

<br />

they are both the Any type,<br />

they are the same primitive type,<br />

they are the same type parameter,<br />

they are union types with identical sets of constituent types, or<br />

they are object types with identical sets of members.<br />

Two members are considered identical when<br />

<br />

<br />

<br />

<br />

<br />

they are public properties with identical names, optionality, and types,<br />

they are private or protected properties originating in the same declaration and having identical<br />

types,<br />

they are identical call signatures,<br />

they are identical construct signatures, or<br />

they are index signatures of identical kind with identical types.<br />

Two call or construct signatures are considered identical when they have the same number of type<br />

parameters with identical type parameter constraints and, after substituting type Any for the type<br />

parameters introduced by the signatures, identical number of parameters with identical kind (required,<br />

optional or rest) and types, and identical return types.<br />

50

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!