Redeclaring is normal? `no-redeclare` eslint rule

Hi, new to ArkType. I'm following the docs and doing stuff like const Foo = type(...); type Foo = typeof Foo.infer . eslint points out that this violates its no-redeclare rule. Of course I can just disable that rule globally or on each such line, but I'm curious if other ArkType+ESLint users do so, or have a different pattern, or a more precise way to disable it just for the ArkType case.
19 Replies
ssalbdivad
ssalbdivad•3w ago
interesting, from the eslint docs:
Note: Even with this option set to true, this rule will report if you name a type and a variable the same name. This is intentional. Declaring a variable and a type the same is usually an accident, and it can lead to hard-to-understand code. If you have a rare case where you're intentionally naming a type the same name as a variable, use a disable comment. For example:
https://typescript-eslint.io/rules/no-redeclare/ maybe I can talk to Josh Goldberg about this beacuse that pattern is quite prevalant not only in ArkType but in other libraries as well. iirc effect uses it a lot
david glasser
david glasserOP•3w ago
hmm, I missed that the docs basically say not to use it
ssalbdivad
ssalbdivad•3w ago
generally I find a 1:1 association between a type and a value very helpful for cases like this
david glasser
david glasserOP•3w ago
By which I mean I asked this question before reading the docs 🙂
ssalbdivad
ssalbdivad•3w ago
it can lead to hard-to-understand code
I don't think is true because there is never any ambiguity even from the immediate context whether something is being used as a type or a value I see how the pattern would take some getting used to if you've never seen it but I don't think it's inherently confusing at all
david glasser
david glasserOP•3w ago
(I don't turn it on explicitly though, I think it's in one of the recommended presets.)
ssalbdivad
ssalbdivad•3w ago
seems like for now you're stuck either using different names/casing or disabling the eslint rule yeah I am surprised I haven't seen more complaints about this honestly
david glasser
david glasserOP•3w ago
also I'm not sure if I'm getting the tseslint or eslint version of the rule
ssalbdivad
ssalbdivad•3w ago
a lot of people don't use the same naming conventions we have in our docs but especially if it's in eslint's default set of rules
david glasser
david glasserOP•3w ago
Ah yeah, it's the normal eslint version, not the one you linked above; the TS one is not "recommended" but the plain one is.
ssalbdivad
ssalbdivad•3w ago
would you consider opening an issue on typescript-eslint and referencing the arktype docs and that other libraries recommend this pattern as well for tightly coupled types + values (in this case schemas)? ahh
david glasser
david glasserOP•3w ago
The TS ESlint one says to disable the non-TS one
david glasser
david glasserOP•3w ago
and the non-TS one says
No description
ssalbdivad
ssalbdivad•3w ago
I think there's a decent likelihood they'd at least be willing to add an option
david glasser
david glasserOP•3w ago
honestly seems like eslint (non TS) should have a like recommendedForTS config it feels like the takeaway here is "TS users should disable no-redeclare, and ArkType should suggest that somewhere"?
ssalbdivad
ssalbdivad•3w ago
hmm yeah maybe, I guess some of the other scenarios mentioned in the docs could be useful so I'd prefer if there was a setting that explicitly just allowed a type and value with the same name but also obviously other than convention there's no inherent reason you have to name things that way, it's just our favorite pattern for defining schemas with standalone types
david glasser
david glasserOP•3w ago
Adding this to my eslint config
// As per its docs, this is unnecessary for TS users who avoid using `var`
// (which we also turn on here). And leaving it on makes common ArkType
// patterns errors.
'no-redeclare': 'off',
'no-var': 'error',
// As per its docs, this is unnecessary for TS users who avoid using `var`
// (which we also turn on here). And leaving it on makes common ArkType
// patterns errors.
'no-redeclare': 'off',
'no-var': 'error',
log(n)
log(n)•2w ago
I name my ark type()s lowercase. They're values after all Solves the problem in the end :shrug:
ssalbdivad
ssalbdivad•2w ago
yeah this used to be our recommendation until a year ago or so. a lot of people like the alignment between the validator and type names

Did you find this page helpful?