Re:TypeScript Is Surprisingly OK for Compilers
by dataangel on Friday August 18, 2023 @12:16PM
(#37177828)
I believe you could have a Protocol that requires the property and that the object is Callable.
[ Parent
| on HN ]
Re:TypeScript Is Surprisingly OK for Compilers
by c-hendricks on Friday August 18, 2023 @12:22PM
(#37177929)
Ah, that's not really that different than in TypeScript then. There you have to define a callable interface, and can add whatever properties you want
interface SomethingCallableWithAnExtraProperty {
// This means you can call it like a function.
(args: Whatever): SomethingReturned
// And since it's an interface, you can still do interface-y things
anotherProperty: string
}