You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixing and supporting this would make the implementation even easier: if the enum is an argument of any call expression (not just some Object.* methods) we could consider all members used. However, the issue is that there's also methods we know should not mark all members as referenced, such as Object.is or any function we don't know the implementation of.
Unfortunately, the type-checker doesn't find references through e.g. z.nativeEnum either (i.e. similar to "Find All References" in an IDE like VS Code). So, there's three options I guess:
consider members referenced if enum is argument in any call expression → we'd miss out on enum members, OR
maintain a list of methods (e.g. Object.keys etc) → even we'd start tracking external methods such as z. nativeEnum then we'd need to make sure z is actually zod (could be imported as any name?), OR
do nothing (i.e. maintain a "safer" list of language built-ins), do nothing, and allow users to ignore, eg:
I'm leaning towards the third option, as at this point I think it should lead to best results. Even though it's potentially a hassle to deal with, it's better than ignorance/blind spots.
@webpro I got another usecase: when you're using const enum you sometimes need to export it so it properly enumerates on tsc compilation, even though it's technically not being imported anywhere.
Moving it to separate file solves the problem, so it probably can be safely ignored.
Prerequisites
Reproduction url
https://github.com/liza-s-orchid/knip-bug
Reproduction access
Description of the issue
In this scenario, there is an enum with initializers:
That enum is imported and used in a zod schema:
With this code, Knip reports each enum member as unused, but effectively, every enumerated value is used in the context of the type definition.
I encountered a similar issue in the following topics (which were resolved):
#699
#703
The text was updated successfully, but these errors were encountered: