mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
Step 2-01 updates
This commit is contained in:
@@ -1,22 +1,32 @@
|
||||
// Interface for an object or class
|
||||
interface Car {
|
||||
make: string;
|
||||
model: string;
|
||||
}
|
||||
|
||||
class MyCar implements Car {
|
||||
make: 'Honda';
|
||||
model: 'Accord';
|
||||
}
|
||||
make: string;
|
||||
model: string;
|
||||
|
||||
const myCar: Car = {
|
||||
constructor(make: string, model: string) {
|
||||
this.make = make;
|
||||
this.model = model;
|
||||
}
|
||||
}
|
||||
const myCar1: Car = new MyCar('Honda', 'Accord');
|
||||
|
||||
const myCar2: Car = {
|
||||
make: 'Honda',
|
||||
model: 'Accord'
|
||||
};
|
||||
|
||||
// Interface as Functions
|
||||
// Interface for a function
|
||||
interface InterestingFn {
|
||||
(someArgs: string): number;
|
||||
}
|
||||
const interesting: InterestingFn = (someArgs: string): number => {
|
||||
return Number(someArgs);
|
||||
};
|
||||
|
||||
// adding an export to turn this into a "module"
|
||||
export default {};
|
||||
|
||||
Reference in New Issue
Block a user