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';
}

Explanation

Both method and property syntax work. With strictFunctionTypes, property syntax gets stricter parameter checks.

Further reading

Problem with a question

TypeScript · Junior · question 72

Test yourself

Take the TypeScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz