TypeScript 1.3
Protected
The newprotected modifier in classes works like it does in familiar languages like C++, C#, and Java. Aprotected member of a class is visible only inside subclasses of the class in which it is declared:
tsclassThing {protecteddoSomething() {/* ... */}}classMyThingextendsThing {publicmyMethod() {// OK, can access protected member from subclassthis.doSomething();}}vart =newMyThing();t.doSomething();// Error, cannot call protected member from outside class
Tuple types
Tuple types express an array where the type of certain elements is known, but need not be the same. For example, you may want to represent an array with astring at position 0 and anumber at position 1:
ts// Declare a tuple typevarx: [string,number];// Initialize itx = ["hello",10];// OK// Initialize it incorrectlyx = [10,"hello"];// Error
When accessing an element with a known index, the correct type is retrieved:
tsconsole.log(x[0].substr(1));// OKconsole.log(x[1].substr(1));// Error, 'number' does not have 'substr'
Note that in TypeScript 1.4, when accessing an element outside the set of known indices, a union type is used instead:
tsx[3] ="world";// OKconsole.log(x[5].toString());// OK, 'string' and 'number' both have toStringx[6] =true;// Error, boolean isn't number or string
The TypeScript docs are an open source project. Help us improve these pagesby sending a Pull Request ❤
Last updated: Dec 16, 2025