GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — Support higher order inferences for constructor functions by ahejlsberg · Pull Request #31116 · microsoft/TypeScript Conversation
|
|
TypeScript Bot (@typescript-bot) test this |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at fcd6f52. You can monitor the build here. It should now contribute to this PR's status checks. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at fcd6f52. You can monitor the build here. It should now contribute to this PR's status checks. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at 4fe59dc. You can monitor the build here. It should now contribute to this PR's status checks. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at 3e79e8d. You can monitor the build here. It should now contribute to this PR's status checks. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Hi Ryan Cavanaugh (@RyanCavanaugh) Anders Hejlsberg (@ahejlsberg), Please find below an adapted example from the one in this PR: declare class Point { constructor(x: number, y: number) readonly x: number readonly y: number } declare class Bag<T> { constructor(...args: T[]) contains(value: T): boolean static foo: string } function asFunction<A extends any[], B>(cf: new (...args: A) => B) { return (...args: A) => new cf(...args) } const newPoint = asFunction(Point) // (x: number, y: number) => Point const newBag = asFunction(Bag) // <T>(...args: T[]) => Bag<T> const p1 = new Point(10, 20) // Point const p2 = newPoint(10, 20) // Point const bag1 = new Bag(1, 2, 3) // Bag<number> const bag2 = newBag('a', 'b', 'c') // Bag<string> declare class Component<P> { props: P constructor(props: P) } interface ComponentClass<P> { new (props: P): Component<P> thisWillBreakGenericInference?: boolean // <--- this is breaking the type inference } declare function myHoc<P>(C: ComponentClass<P>): ComponentClass<P> type GenericProps<T> = { foo: number; stuff: T } declare class GenericComponent<T> extends Component<GenericProps<T>> {} // Should be: // const GenericComponent2: new <T>(props: GenericProps<T>) => Component<GenericProps<T>> // Actually: // const GenericComponent2: ComponentClass<GenericProps<unknown>> const GenericComponent2 = myHoc(GenericComponent) Link to playground: The issue here is that React's ComponentClass interface has a few optional members defined. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@guykr-stratoscale That's a known limitation. See discussion in #30650 (comment). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It's really encouraging that TS is getting some more support for functional programmers. Keep up the good work! Small critique on the announcement docs. The function you guys are showing off as function compose<T, U, V>( f: (x: T) => U, g: (y: U) => V): (x: T) => V { return x => g(f(x)) } Based on all of the below resources: -- Haskell (.) :: (b -> c) -> (a -> b) -> a -> c // Sanctuary.js compose :: Semigroupoid s => s b c -> s a b -> s a c // fp-ts export interface Semigroupoid<F> { readonly URI: F readonly compose: <E, A, B>(ab: HKT2<F, A, B>, la: HKT2<F, E, A>) => HKT2<F, E, B> } // Ramda (b -> c) -> (a -> b) -> a -> c // Crocks composeB :: (b -> c) -> (a -> b) -> a -> c I understand the the announcement docs are just for simple illustration, and it's great. I'm thrilled about the attention to the functional side of javascript. But it would be nice to have simple and correct code for the docs, maybe something like: type fn1<I, O> = (i: I) => O type compose = <T extends any, U, V>(f: fn1<U, V>) => (g: fn1<T, U>) => fn1<T, V> const compose: compose = f => g => a => f (g (a)) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Higher order type inference from generic React component
There was an error while loading. Please reload this page.