# How I fixed some trouble importing types in .d.ts files

> How I fixed TypeScript types not being picked up in a .d.ts file, like an Astro env.d.ts, by switching from a top-level import to an inline import() type.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2024-03-27 | Topics: [TypeScript](https://flaviocopes.com/tags/typescript/), [Astro](https://flaviocopes.com/tags/astro/) | Canonical: https://flaviocopes.com/how-i-fixed-some-trouble-importing-types-in-dts-files/

I had some trouble making something work in my [Astro](https://flaviocopes.com/astro-introduction/) site.

I used [Astro locals](https://flaviocopes.com/using-astro-locals/) and I had to type a variable I shared using locals.

So I went and added that to the `src/env.d.ts`, [as the docs say](https://docs.astro.build/en/guides/middleware/#middleware-types).

But my types weren’t picked up.

My code looked like this:

```typescript
/// <reference types="astro/client" />
import { sometype } from 'somelib'

declare namespace App {
  interface Locals {
    somevariable: sometype
  }
}
```

What I discovered thanks to [this SO answer](https://stackoverflow.com/a/51114250) is, we can’t do imports like this in `.d.ts` files.

So I imported the type in another file, and then I imported the type from that file, like this:

> `typesforenvdts.ts`

```typescript
import { sometype } from 'somelib'

export { sometype }
```

> `env.d.ts`

```typescript
/// <reference types="astro/client" />

declare namespace App {
  interface Locals {
    somevariable: import('./typesforenvdts').sometype
  }
}
```

Don’t ask me why, but now it works.
