#Type arguments for Array circularly reference themselves

1 messages · Page 1 of 1 (latest)

topaz heronBOT
#
balam314#0

Preview:ts /**Stores the JS type used for each pseudocode variable type */ export type VariableTypeMapping<T> = T extends PrimitiveVariableType<infer U> ? ( //! deleting <infer U> fixes the error T["name"] extends "INTEGER" ? number : T["name"] extends "DATE" ? Date : ...

whole palm
#

I've found a workaround... but what the heck is happening here??

#

Why do I get that error by adding an unused infer, and why does it go away by deleting unused methods

whole palm
#

!helper

cursive stag
#

i haven't reasoned through the details, but here's a simplified repro:

topaz heronBOT
#
mkantor#0

Preview:ts type VariableTypeMapping<T> = T extends PrimitiveVariableType<infer U> ? //! deleting <infer U> fixes the error T['name'] extends 'INTEGER' ? number : never : Array<VariableTypeMapping<ArrayElementVariableType>> //Type arguments for Array circularly reference themselves ...

cursive stag
#

here's an even-more-simplified repro, which eliminates some of the mystery //! cases from the previous repro, but i think gets at the crux of the issue?

topaz heronBOT
#
mkantor#0

Preview:```ts
type VariableTypeMapping<T> =
T extends PrimitiveVariableType
? never
: Array<
VariableTypeMapping<EnumeratedVariableType>
> //Type arguments for Array circularly reference themselves

type PrimitiveVariableType = {x: () => never}
type EnumeratedVariableType = {x: VariableValue}
...```

whole palm
# topaz heron

hmm, this isn't quite right... it directly allows arrays of other arrays

#

also, in that version, specifying the return type for x() doesn't fix the error

#

The issue is fairly obvious, it's that Array<> can have other arrays in it (one level down, through a pointer)