I looked for duplicates, perhaps this is related?
#5863
Not sure...
Suppose we have some IO function that returns an object. In Javascript, Classes are more or less just functions
const IO = f => ({
f,
map: g => IO( (...args) => g ( f(...args) ) ) ,
join: () => f()
})
IO.of = (val) => IO(()=>val)
The of class function raises an issue with Property 'of' does not exist on type '(f: any) => { f: any; map: (g: any) => any; join: () => any; }'.
Expected behavior is that TS understands that of is a property or "static method" of sorts on the IO function.
The error goes away by doing one of the following
const IO = (f => ({
f,
map: g => IO( (...args) => g ( f(...args) ) ) ,
join: () => f()
})) as any
Or something like this
interface P {
f: any,
map: (f) => P,
join: any
}
interface F {
(f): P;
of: (f) => P;
}
const IO = (f => ({
f,
map: g => IO( (...args) => g ( f(...args) ) ) ,
join: () => f()
})) as F
IO.of = (val) => IO(()=>val)
It seems that of should be inferred without this however. Also, in the later example, Intellisense doesn't seem to realize that map return a new copy of P interface but that is probably news for a different team ;-)
I looked for duplicates, perhaps this is related?
#5863
Not sure...
Suppose we have some
IOfunction that returns an object. In Javascript, Classes are more or less just functionsThe
ofclass function raises an issue withProperty 'of' does not exist on type '(f: any) => { f: any; map: (g: any) => any; join: () => any; }'.Expected behavior is that TS understands that
ofis a property or "static method" of sorts on the IO function.The error goes away by doing one of the following
Or something like this
It seems that
ofshould be inferred without this however. Also, in the later example, Intellisense doesn't seem to realize thatmapreturn a new copy ofPinterface but that is probably news for a different team ;-)