Open ari-becker opened 1 year ago
PgEnum<[string, ...string[]]>
@dankochetov that would be fine, but that also results in a type error :(
I'm also curious, isn't foo
not typed correctly? Why do you want to annotate it?
I'm also curious, isn't
foo
not typed correctly? Why do you want to annotate it?
@Angelelz I've been bit by TS2742 ("the inferred type of X cannot be named without a reference to Y, this is likely not portable") a few too many times, and so I've developed a reflex to just add the type annotation when it's simple / brainless to do so. It just makes development smoother versus tripping over TS2742 later on and trying to figure out the type annotation later.
Describe what you want
Here's the user story of writing a new
PgEnum
:pgEnum
:Cool, simple, works, compiles. But the type is only inferred here, rather than checked / enforced. So let's try to add a
satisfies
:Ah,
PgEnum
requires a type parameter. Let's add one:Green again. But now I've duplicated the enum values into both the enum definition and into the type-check. Can we DRY?
Not quite, the type parameter doesn't accept
readonly
. Let's find a trick on Stack Overflow:Great, back to green. But this feels very awkward / boilerplate...? Is it not possible to have either
satisfies PgEnum;
(similar toPgTable
), without specifying a type parameter, or have the type parameter acceptreadonly
so that it can usetypeof
anas const
array?