Project Types
What is it
Some JS libraries include typing file so they work with Typescript project without additional work.
But in case a library does not have a declaration file, you need to install the type package
separately.
yarn add --dev @types/package-name
Ambient Declaration
Ambient declaration is a way to define types
, variables
, functions
, or other entities
without providing their actual implementation.
- These declarations describe the shape of code, allowing TypeScript to know about it for type-checking and tooling purposes.
--dev
--dev
is indicating a dev dependency installation.
Dev dependency are things that are not direct dependencies for your project.
- will not be included in the bundle.
This is a good place to install typescript types declarations because they're only used in the build process.
Declaration File (.d.ts
)
.d.ts
file is a declaration file.
- Defines type information for JS code.
- Enables JS libraries to be used in TypeScript projects with proper type checking and autocompletion.
// js file: util.js function sayHello(name) { console.log("Hello, " + name); } // d.ts file: util.d.ts declare function sayHello(name: string): void;