interface Foo {
bar: number;
bas: string;
}
var foo = {} as Foo;
// ahhhh .... forget something?
interface Foo {
bar: number;
bas: string;
}
var foo = <Foo>{
// the compiler will provide autocomplete for properties of Foo
// But it is easy for the developer to forget adding all the properties
// Also this code is likely to break if Foo gets refactored (e.g. a new property added)
};
interface Foo {
bar: number;
bas: string;
}
var foo:Foo = {
// the compiler will provide autocomplete for properties of Foo
};
function handler (event: Event) {
let mouseEvent = event as MouseEvent;
}
function handler(event: Event) {
let element = event as HTMLElement; // Error: Neither 'Event' nor type 'HTMLElement' is assignable to the other
}
function handler(event: Event) {
let element = event as any as HTMLElement; // Okay!
}