Thomas Boyt
Front-end engineer
function multiply(a, b) {
return a * b;
}
const one = 1;
const two = 'two';
const three = multiply(one, two); // NaN!
function multiply(a: number, b: number): number {
return a * b;
}
const one = 1;
const two = 'two';
const three = multiply(one, two); // Still NaN!
app.ts(8,29): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
interface Person {
firstName: string;
lastName: string;
}
const thomas: Person = {
firstName: 'Thomas',
lastName: 'Boyt',
};
interface Person {
firstName: string;
lastName: string;
}
const thomas: Person = {
firstName: 'Thomas',
middleName: 'Albert',
lastName: 'Boyt',
};
slides.ts (8,3): Type '{ firstName: string; middleName: string; lastName: string; }' is not assignable to type 'Person'. Object literal may only specify known properties, and 'middleName' does not exist in type 'Person'. (2322)
interface Person {
names: string[];
}
const me: Person = {
names: ['thomas', 'boyt'],
};
// firstName is inferred to be string
const firstName = me.names[0];
By Thomas Boyt