0

I know the TypeScript documentation is not entirely up to date as the type and abstract keywords are not mentioned. For example the following is now valid TypeScript:

interface A {
    b: string;
}

// I can't see anywhere in documentation this is mentioned.
type C = A;
var d: C;

d.b = 'something';

Is there a better place to get up to date documentation apart from parsing the source code or reading all the latest changes on GitHub issues?

AJP
  • 26,547
  • 23
  • 88
  • 127
  • Possible duplicate of [What is the "type" reserved word in TypeScript?](http://stackoverflow.com/questions/31364693/what-is-the-type-reserved-word-in-typescript) – Dark Falcon Dec 11 '15 at 18:41
  • Probably the language spec, as referenced in that answer. The handbook is probably meant to be a more readable introduction, and thus doesn't cover everything. – Dark Falcon Dec 11 '15 at 18:42
  • https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages – Ryan Cavanaugh Dec 11 '15 at 18:52

2 Answers2

1

It's called Type Aliases to make your code more readable, and you can use it like this:

type PrimitiveArray = Array<string|number|boolean>;
type MyNumber = number;
type NgScope = ng.IScope;
type Callback = () => void;
gilamran
  • 7,090
  • 4
  • 31
  • 50
  • Brtill, thanks. Where did you learn that from? Was it another language that on "playing with" `type` in TypeScript you realised works the same way? – AJP Dec 12 '15 at 06:46
  • Ok I see it in the [1.4 sneek peak](http://blogs.msdn.com/b/typescript/archive/2014/11/18/what-s-new-in-the-typescript-type-system.aspx) – AJP Dec 12 '15 at 06:56
1

Edit: It's mentioned in the docs as well.

Not in the docs, but it's here.

Type Aliases

You can now define an alias for a type using the type keyword:

type PrimitiveArray = Array<string|number|boolean>; 
type MyNumber = number; 
type NgScope = ng.IScope; 
type Callback = () => void; 

Type aliases are exactly the same as their original types; they are simply alternative names. You can use these aliases to better document your code and aid readability.

Louay Alakkad
  • 7,132
  • 2
  • 22
  • 45
  • Good link. I've been looking at the "docs" on: http://www.typescriptlang.org/Handbook Will swap to using the github repo. Thanks. \*edit\* ah and good they have a [TODO to document abstract classes](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#8-classes)... which makes much more sense than "silence" :) – AJP Dec 12 '15 at 06:53