I've got a typescript method that returns a structured object:
export interface LoginResult{
success:Boolean,
message:String
}
login():LoginResult{
...
// do login logic
return {
success: successVal,
message: messageVal
}
}
Rather than having to define the interface distinctly though I would like to be able to simply define the return type inline as part of the method call, something like the following:
login():LoginResult:{success:Boolean, message:String}{
...
// do login logic
return {
success: successVal,
message: messageVal
}
}
Is this possible and if so what is the correct syntax?
login(): { success: boolean, message: string } { ... }, but you can't then name the type. - jonrsharpebooleanandBooleantypescriptlang.org/docs/handbook/declaration-files/… - Aleksey L.