--- title: "add types to a javascript when using typescript" date: 2021-07-12T11:12:32+02:00 draft: false snippet_types: - js - typescript --- Today I had a .js file that I needed to import into the rest of a TypeScript app but could not convert it to a .ts file. To get around this limitation I added an accompanying .d.ts file. countryConfig.js ```js const countries = [ { code: 'de', domainExtension: '.de' }, ... ]; exports.countries = countries; ``` countryConfig.d.ts ```typescript interface Country { code: string; domainExtension: string; } export const countries: Array; ``` app.ts ```typescript import countries from './countryConfig' ... ``` source: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html