Here is a function that I need to create a validator for:
function (n: number) {
return {s: n};
}
I have come across two options for creating the validator:
Option 1: Interface
interface ValidatorFnInterface {
(n: number): {
[key: string]: any;
};
}
Option 2: Type alias
type ValidatorFnType = (n: number) => {
[key: string]: any
};
These can be used as shown below:
let f1: ValidatorFnInterface = function (n: number) {
return {s: n};
};
let f2: ValidatorFnType = function (n: number) {
return {s: n};
};
In Typescript, lib.d.ts
uses type aliases, while Angular2 code uses interfaces. When deciding between the two, is there a specific logic to follow or is it solely based on preference?