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
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
hmm, I missed that the docs basically say not to use it
generally I find a 1:1 association between a type and a value very helpful for cases like this
By which I mean I asked this question before reading the docs 🙂
it can lead to hard-to-understand codeI 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
(I don't turn it on explicitly though, I think it's in one of the recommended presets.)
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
also I'm not sure if I'm getting the tseslint or eslint version of the rule
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
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.
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
The TS ESlint one says to disable the non-TS one
and the non-TS one says

I think there's a decent likelihood they'd at least be willing to add an option
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"?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
Adding this to my eslint config
I name my ark
type()s lowercase. They're values after all
Solves the problem in the end :shrug: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