While no actual Turing machine’s tape is infinitely long, I found issues in TypeScript with how finite generics are. You have to define every possible count of generic arguments if you want to preserve their types. And if you go above that count your type system degrades. I think there’s also a maximum of 7 or so before it doesn’t work. Beyond that and the generic type widens. For example, Lodash enumerating types fo…
This was fixed in Typescript 4.0, with the introduction of variadic tuples: https://www.typescriptlang.org/docs/handbook/release-notes/t...
Functional Programming with TypeScript's Type System
11–20 of 46 posts
Re: Functional Programming with TypeScript's Type System
#12Re: Functional Programming with TypeScript's Type System
#13Re: Functional Programming with TypeScript's Type System
#14It is obviously very powerful and can model very complex type constraints.
But then you have stuff like this where it is not checking types as I would expect:
interface Foo { bar: string; }
const f = {bar: "foobar"} as Readonly;
function someFunc(): Foo {
return f; // No error or warning, even with all strict flags enabled
}Re: Functional Programming with TypeScript's Type System
#15I don't get TypeScript's type system. It is obviously very powerful and can model very complex type constraints. But then you have stuff like this where it is not checking types as I would expect: interface Foo { bar: string; } const f = {bar: "foobar"} as Readonly ; function someFunc(): Foo { return f; // No error or warning, even with all strict flags enabled }
Re: Functional Programming with TypeScript's Type System
#16Try to type a flatMap and then we talk.
Re: Functional Programming with TypeScript's Type System
#17I don't get TypeScript's type system. It is obviously very powerful and can model very complex type constraints. But then you have stuff like this where it is not checking types as I would expect: interface Foo { bar: string; } const f = {bar: "foobar"} as Readonly ; function someFunc(): Foo { return f; // No error or warning, even with all strict flags enabled }
Sorry, I don't get it. What do you expect to happen here?
I should note that I haven't yet had the pleasure of using a language that handles const-ness properly, as Readonly should be neither a subtype nor a supertype of T
Re: Functional Programming with TypeScript's Type System
#18I don't get TypeScript's type system. It is obviously very powerful and can model very complex type constraints. But then you have stuff like this where it is not checking types as I would expect: interface Foo { bar: string; } const f = {bar: "foobar"} as Readonly ; function someFunc(): Foo { return f; // No error or warning, even with all strict flags enabled }
Re: Functional Programming with TypeScript's Type System
#19Try to type a flatMap and then we talk.
type ValueOrArray = T | Array>;
type FlatMap = (array: Array, fn: (el: In) => ValueOrArray) => Array;Re: Functional Programming with TypeScript's Type System
#20I don't get TypeScript's type system. It is obviously very powerful and can model very complex type constraints. But then you have stuff like this where it is not checking types as I would expect: interface Foo { bar: string; } const f = {bar: "foobar"} as Readonly ; function someFunc(): Foo { return f; // No error or warning, even with all strict flags enabled }