4 ms·
function foo<T>(x: T & {field: number}): T { return x; } function bar<T>(x: T & {field: number}): T { const x0 = foo(x); //
by dwohnitmok 6y ago
function foo<T>(x: T & {field: number}): T {
return x;
}
function bar<T>(x: T & {field: number}): T {
const x0 = foo(x);
// type error because x0 doesn't have field
// would compile fine with row types
const x1 = foo(x0);
return x1;
}
Yes it's true. I also sorely miss the lack of row types in Haskell (I miss them even in something like Idris where you can create them more easily, but it's still not great compared to first-class support).
EDIT: I may be being dumb. You could probably fix this by adding an intersection type again on the right-hand side. I think there was something else I was missing from TS, but I'll have to noodle on it a bit more.
- dllthomas 6y agoNot dumb, you answered the question I asked :D But yeah, I agree that duplicating the intersection produces another interesting question. In any case, "convenient approximation of row types" probably still applies to TS more than Haskell. And possibly also "more convenient row types", but that remains TBD.