#"File '../index.d.ts' is not a module" errors after updating to TypeScript 5.1

10 messages · Page 1 of 1 (latest)

timid vine
#

Hi!

I inherited an old app written in JS that uses JSDoc to add types. It has a bunch of index.d.ts files where namespaces and types are declared, e.g.:

declare namespace AB.API {}

These namespaces and types are are later used in JS files in JSDoc comments:

/**
 * @param {AB.API.RequestArguments} requestArguments
 * @returns {Array<string>}
 */
const requestArgumentsErrors = (requestArguments) => ...

These index.d.ts are added in tsconfig.json via typesRoot options:

"typeRoots": [
  "./typings",
  "node_modules/@types"
],

As in the title, after upgrading TS to 5.1.x I'm getting File '../index.d.ts' is not a module errors. Is there some option I can change to make it work as before?

Cheers!

upper cloud
#

do you have isolatedModulesenabled? @timid vine

#

also, try addingan extra import to your typing file

#

like so

export {};
#

it should solve it

#

but yeah, you should have imports in your typings file

#

don't know what version you upgraded from, but it has been that way for quite some time now

timid vine
#

do you have isolatedModulesenabled?
Nope. I've just added it, but setting it to true or false doesn't make any difference.

The full path of index.d.ts file I mentioned earlier is typings/api/index.d.ts and it has only this code:

declare namespace AB.API {}

Other index.d.ts extend this interface.

also, try addingan extra import to your typing file
In this case I'm getting the following error:
Module '"api"' has no exported member 'getWhatever'
in places where I've got code like:

import { getWhatever } from 'api';

where api.js re-exports a bunch of exports from other JS files. When I CMD + click on 'api' in import { getWhatever } from 'api' I'm ending up in the typings/api/index.d.ts file, not in the api/index.js file or the actual file from which this function was re-exported :/