TypeScript Interface Methods vs Function Properties

TypeScript Interface Methods vs Function Properties

In a TypeScript interface, save(): void declares a method signature. save: () => void declares a property whose value is callable. Both describe a contract; neither creates a function or binds this. There is also a type-checking difference: with strictFunctionTypes, function properties receive stricter parameter checking than method signatures. 1interface MethodContract { 2 save(): void; 3} 4 5interface PropertyContract { 6 save: () => void; 7} These are separate interfaces so we can compare the alternatives without declaring the same member twice. ...

January 9, 2024 · 4 min
Difference between var, const and let

Difference between var, const and let

There are 3 ways to declare a variable in JavaScript: using one of the keywords var, const or let. Prior to ES6, var used to be the only way to declare a variable. You had no other choice. However, it had some weird and unexpected behavior, which often resulted in hard to debug errors. Intuitively, you would think variable declared with var is block scoped. Variable declared in, for example, if statement, or a for loop, is visible only in the scope of that statement or loop. ...

May 6, 2020 · 3 min
Privacy and cookie settings