Static Typing for Your Own TypeScript Code
This is how adding type information to TypeScript variables looks like:
// anyObject hold values of any arbitrary type
var anyObject: any;
// count is a number
var count: number;
// regexPatterns is an array of regular expressions
var regexPatterns: RegExp;
// reverse is a function which accepts and returns a string
var reverse: (input: string) => string;
If you immediately assign a value to a variable that isn't explicitly typed, the TypeScript compiler will find out the correct type for you. This is what's called type inference. Here's what the Visual Studio tooling will show you when you hover over the variable name:
You can even use generic types in your declarations or define your own type interfaces, but that's beyond the scope of this post, which focuses on type definition files.
.d.ts, where d stands for definition. Type definition files make it possible to enjoy the benefits of type checking, autocompletion, and member documentation:
… and a lot more.
ReSharper will then include the found types in its autocompletion list, given that you've got TypeScript installed: