Running tslint on my code I get this error:
expected variableDeclarator: 'getCode' to have a typedef.
for a TypeScript file:
export var getCode = function (param: string): string {
// ...
};
How do I improve this so I don't see the tslint error?
You have to explicitely add a type declaration to your variable.
export var getCode : (param: string) => string = function (param: string): string {
//...
}
You said this looks pretty unreadable. Well, yes, anonymous types makes TS code look worse, especially when they are huge. In that case, you can declare a callable interface, like this:
export interface CodeGetter {
(param: string): string;
}
export var getCode: CodeGetter = function(param: string): string { ... }
You can check whether tslint allows you (I can't check it right now) to drop type declaration in definition of the function when using the interface
export interface CodeGetter {
(param: string): string;
}
export var getCode: CodeGetter = function(param) { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With