pzavolinsky / ts-unused-exports

ts-unused-exports finds unused exported symbols in your Typescript project
MIT License
749 stars 49 forks source link

Does it support tsx files? #27

Closed testerez closed 5 years ago

testerez commented 6 years ago

I quickly tried this on a projet but most detected unused exports were actually used in tsx files. Is it a known limitation?

pzavolinsky commented 6 years ago

Hi @testerez , it should support TSX no problem.

Below's a working example.

Double check the tsconfig.json and it you've found an unsupported case, please include a minimal example that doesn't work.

Cheers!

Here's the example:


package.json

{
  "dependencies": {
    "@types/react": "^16.4.18",
    "react": "^16.6.0",
    "ts-unused-exports": "^2.0.11"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "outDir": "./dist",
    "jsx": "react"
  },
  "include": [
    "./src/**/*.ts",
    "./src/**/*.tsx"
  ]
}

src/comp.tsx

import * as React from 'react';
import { thisOneIsUsed } from './util';

const Comp = ({ a }:{ a: string }) => <div>{thisOneIsUsed}{a}</div>;

console.log(Comp);

src/util.ts

export const thisOneIsUsed = 1;
export const thisOneIsNot = 2;

$ npm i
$ ./node_modules/.bin/ts-unused-exports tsconfig.json 
1 module with unused exports
src/util: thisOneIsNot
testerez commented 6 years ago

Thanks @pzavolinsky I'll give it a deeper try when I find time for it.

mrseanryan commented 5 years ago

Closing - we can add some example cases to match.