My goal is to write code that utilizes Object methods properly and ensures accurate function inference.
const P = <T,>(x: T) => ({ "foo": (R: Function) => R(x) });
const f = (a: number) => a + 1;
const g = (a: number) => a.toString();
const p1 = f(5); //const p1: number // good
const p2 = g(5); //const p2: string // good
const q1 = P(5)['foo'](f); //const q1: any // bad
const q2 = P(5)['foo'](g); //const q2: any // bad
console.log(q1);
console.log(q2);
Any suggestions or insights are appreciated. Thank you!
"use strict";
const P = (x) => ({ "foo": (R) => R(x) });
const f = (a) => a + 1;
const g = (a) => a.toString();
const p1 = f(5); //const p1: number // good
const p2 = g(5); //const p2: string // good
const q1 = P(5)['foo'](f); //const q1: any // bad
const q2 = P(5)['foo'](g); //const q2: any // bad
console.log(q1);
console.log(q2);