An introduction
var numbers : number[] = [1, 2, 3, 4];
// Implicit type: string[]
var strings = numbers.map(toString);
function toString(n : number) {
return n.toString()
}
var numbers : number[] = [1, 2, 3, 4];
// Implicit type: string[]
var strings = numbers.map(toString);
function toString(n : number) {
return n.toString()
}
// todo-helpers.ts
import * as _ from 'lodash';
import { Todo } from './classes/todo';
export function completeTodos(todos: Todo[]) {
return todos.filter(t => _.assign(t, { complete: true }));
};
class Stack<T> {
_list: T[];
constructor() {
this._list = [];
}
pop() : T {
return this._list.pop();
}
push(item : T) {
this._list.push(item);
}
}
const stack = new Stack<number>();
stack.push(1);
stack.push(2);
stack.pop();
//>> 2
import * as React from 'react';
interface IEventProps {
id: string;
name: string;
description: string;
}
export class Event extends React.Component<IEventProps, any> {
render() {
const url = `/events/${this.props.id}`;
return (
<div className="event">
<a href={url}>{this.props.name}</a>
<div>{this.props.description}</div>
</div>
);
}
}
const events = (window as any).bootstrap.events as IEvent[];
const eventListNode = document.getElementById('js-event-list');
ReactDOM.render(<EventList events={events} />, eventListNode);
Working with third party libraries requires installation of a type definition file that describes the library's API.
Its possible to use libraries without installing a type definition file; however, this can be awkward.
Type Definition Project