tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.95k stars 251 forks source link

Could not find a declaration file for module 'qs' #794

Open dac-humi opened 3 days ago

dac-humi commented 3 days ago

Ziggy version

2.4.1

Laravel version

10.48.24

Description

In a Laravel/React/Inertia.js project, we go with the recommendation to get TypeScript types directly from the composer packages, see:

Today, after upgrading to latest and doing yarn install; yarn build, we get this in CI/CD

vendor/tightenco/ziggy/src/js/index.d.ts:1:26 - error TS7016: Could not find a declaration file for module 'qs'. '/var/www/hr/node_modules/qs/lib/index.js' implicitly has an 'any' type. Try `npm i --save-dev @types/qs` if it exists or add a new declaration (.d.ts) file containing `declare module 'qs';`

Or this in local:

vendor/tightenco/ziggy/src/js/index.d.ts:1:26 - error TS7016: Could not find a declaration file for module 'qs'. '/Users/dac.chartrand/code/github/Humi-HR/humility/applications/hr/node_modules/qs/lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/qs` if it exists or add a new declaration (.d.ts) file containing `declare module 'qs';`

1 import { ParsedQs } from 'qs';
                           ~~~~

Found 1 error in vendor/tightenco/ziggy/src/js/index.d.ts:1

Ziggy call and context

yarn build

Ziggy configuration

// tsconfig.json
{
    "compilerOptions": {
        "allowJs": true,
        "module": "ESNext",
        "moduleResolution": "bundler",
        "jsx": "react-jsx",
        "strict": true,
        "isolatedModules": true,
        "target": "ESNext",
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "noEmit": true,
        "paths": {
            "@/*": ["./resources/js/*"],
            "@images/*": ["./resources/images/*"],
            "ziggy-js": ["./vendor/tightenco/ziggy"]
        }
    },
    "include": ["resources/js/**/*.ts", "resources/js/**/*.tsx", "resources/js/**/*.d.ts"]
}

Route definition

n/a
dac-humi commented 3 days ago

(We want to avoid adding @types/qs to our own package.json. It's not very maintainable if we have to play catch up.)

bakerkretzmar commented 3 days ago

Ugh, sorry about this. Probably best for us to just manually copy in the ParsedQs type. I'll work on it.