Avatar ·

What are *.d.ts files in TypeScript and why are they needed?

Hello everyone! I recently started learning TypeScript and came across something I don't understand. In projects, I often see files with the `.d.ts` extension. For example, there's a `node_modules` folder, and inside libraries there are such files. I opened one of them, and there was something like: ```typescript declare module 'lodash' { export function chunk(array: T[], size?: number): T[][]; } ``` I don't quite understand what this is. Is it some kind of separate TypeScript file type? Why are they needed if we have regular `.ts` files? I tried creating such a file myself and writing some code there, but the compiler complains when I try to declare variables without the `declare` keyword. I also noticed that if I write `import` from a library that doesn't have such files, TypeScript throws an error.