TypeScript · Junior · Question 72 of 75
How do you describe an object with a method in a type?
interface Logger {
log(message: string): void;
level: 'info' | 'debug';
}- ✓Correct answer: Use method syntax
log(message: string): void(or a function-typed property) - 2Methods can only be declared in classes
- 3Use
log: method
Explanation
Both method and property syntax work. With strictFunctionTypes, property syntax gets stricter parameter checks.