From O'Reilly "Understanding Typescript" video course
Cameron had a great question, why does the following code compile when the output method signature on the object does not match the interface?
interface Complex {
data: number[];
output: (all: boolean) => number[];
}
const complex: Complex = {
data: [100, 3.99, 10],
output(): number[] {
return this.data;
},
};
See Microsoft Typescript wiki for their explanation.
{
"noImplicitAny": true,
"noUnusedParameters": true,
"sourceMap": true,
"strictNullChecks": true
}
- Unused parameters can be prefixed with _ to avoid error.
- strict null checks disallow reassigning null to a variable.
class Person {
name: string; // default is public
private ssn: number;
protected age: number;
// username will be created as a public field
constructor(name: string, public username: string) {
this.name = name;
}
}
If you have an O’Reilly account, I recommend the author Remo H. Jansen.
Learning Typescript 2x by Remo Jansen