gustavopch / tsc-files

A tiny tool to run `tsc` on specific files without ignoring tsconfig.json
MIT License
233 stars 49 forks source link

Cannot find module '../images/some.svg' or its corresponding type declarations #32

Closed adrianiskandar closed 2 years ago

adrianiskandar commented 2 years ago

Hi, so that issue is easy to fix if you add a custom.d.ts file with this information:

declare module '*.svg' {
  const content: string;
  export default content;
}

And then you add custom.d.ts file to the "include" array in tsconfig.json:

{
  "include": ["custom.d.ts", "**/*.ts", "**/*.tsx"],
  "compilerOptions": {
    "moduleResolution": "node",
    ...other options
    },
    "noEmit": true
  }
}

However, looks like tsc-files temp config files is DELETING everything inside the include array, when it runs it creates something like this:

{
  "include": [],
  "compilerOptions": {
    "lib": [
      "DOM",
      "DOM.Iterable",
      "ES2019"
    ],
    "isolatedModules": true,
    "esModuleInterop": true,
    "jsx": "react-jsx",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "target": "ES2019",
    "strict": true,
    "baseUrl": ".",
    "paths": {
      "~/*": [
        "./app/*"
      ]
    },
    "noEmit": true,
    "skipLibCheck": true
  },
  "files": [
    "app/components/staged.component.tsx"
  ]
}

So when you import .svg or .css or any other type of file that needs declaration in the custom.d.ts file it fails. Do you know how we can work around this? or can we pass specific files we don't want to delete from the include array?

Thanks!

gustavopch commented 2 years ago

Same as https://github.com/gustavopch/tsc-files/issues/20. You can call tsc-files custom.d.ts my-file.ts as suggested here https://github.com/gustavopch/tsc-files/issues/20#issuecomment-996124875.