-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive on import * as S from './file'
#529
Comments
I guess the false positive is Yeah I don't think there's a way for Knip to infer that. If the types are known Knip should be able to infer, but Example of a pattern that Knip is able to work with: https://github.com/webpro/knip/blob/main/packages/knip/fixtures/re-exports-ns-type/index.ts |
I would expect For me, the false positive is h1, h2, and any other export in the file |
From your example there's no way to infer that.
No. Also see https://knip.dev/blog/knip-v5
From your example, I would expect |
Hmm I think some people might want to "turn on" counting star imports as "everything is used". Consider something like this: /// file assets.tsx
export { default as cat } from 'myproject/assets/pictures/at.png';
...
export { default as dog } from 'myproject/assets/pictures/dog.png';
/// file Picture.tsx
import * as pictures from '../assets.tsx';
export type PictureToken = keyof typeof pictures;
interface Props {
pictureToken: PictureToken;
}
export const Picture = (props : Props) => {
/// some code which abstracts getting actual asset from the dictionary, resizing, etc. etc.
} And note that it might actually be impossible to detect in compile-time if e.g. a |
Not sure how the intermediate
Knip does static analysis only, it does indeed not run code and check values dynamically. |
Hmm I think there's a little misunderstanding. I know knip doesn't check values dynamically 😄 ...
const pictureToken = getPictureTokenFromServer(); // dynamic value
return (<Picture pictureToken={pictureToken} />);
... |
Gotcha. That's "too dynamic" indeed. Knip v3 might deal with this better, but it got too slow. TypeScript's language service |
🚀 This issue has been resolved in v5.3.0. See Release 5.3.0 for release notes. |
For the examples in this thread: with proper types, Knip should find references. Played a bit with some scenarios and added to the fixtures: https://github.com/webpro/knip/blob/main/packages/knip/fixtures/re-exports-ns-type/index.tsx Specific to the This functionality hasn't changed in the latest release, I've just added the fixture to confirm it's working as I would expect. |
Not sure if this is going to be in scope for Knip as it seems like an edge case, but the following pattern is causing a false positive.
The text was updated successfully, but these errors were encountered: