Fehler "Could not find a declaration file for module" in TypeScript – wie beheben?
Hallo! Ich bin ein TypeScript-Anfänger und habe ein Problem beim Import eines Drittanbieter-Moduls. Ich habe ein einfaches Express.js-Projekt, das in TypeScript geschrieben ist. Ich habe das Paket `lodash` über npm installiert, aber wenn ich versuche, es in meiner Datei `index.ts` zu importieren, gibt der Compiler einen Fehler aus.
Hier ist mein Code:
```typescript
import _ from 'lodash';
const arr = [1, 2, 3, 4, 5];
const shuffled = _.shuffle(arr);
console.log(shuffled);
```
Beim Ausführen von `tsc` erhalte ich:
```
Could not find a declaration file for module 'lodash'. '/path/to/node_modules/lodash/lodash.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/lodash` if it exists or add a new declaration (.d.ts) file containing `declare module 'lodash';`
```
Ich verstehe, dass TypeScript Deklarationsdateien (`.d.ts`) für Drittanbieter-Module benötigt, aber ich verstehe nicht ganz, wie das funktioniert. Warum funktionieren manche Module ohne zusätzliche Schritte und andere nicht? Und was bedeutet "implicitly has an 'any' type"? Ich
Noch keine Antworten.
Anmelden um eine Antwort zu hinterlassen