Use a TypeScript Definition Without Importing

There may come a time where you want to reference types in your TypeScript file without importing the code. This is common if you have a script tag somewhere else that is importing JavaScript from a public CDN of a popular library.

To import the type definition without importing the library, you can use the triple slash refence tag:

/// <reference types="stripe-v3" />

This will attempt to get the type definition named stripe-v3 that you installed with NPM. If TypeScript has trouble finding it, you can use path instead:

/// <reference path="path/to/file" />

Matt Ferderer

Software engineer who spends his time learning about building teams, project management, software architecture, C#, .NET Core, Blazor, JavaScript, TypeScript, Azure, user experience, web security, and performance.

comment

Comments