Currently learning typescript and in the process of converting a large program from javascript. While fixing errors and adding types, I'm stuck on this one particular issue.
Here's myModule.ts:
export const foo = { ... }
export const bar = { ... }
And here's myFile.ts:
import * as myModule from './myModule'
function doesSomething(input: string) {
return myModule[input]
}
The Typescript compiler is throwing an error: Element implicitly has an 'any' type because type 'typeof "./myModule"' has no index signature.
I've attempted declaring a module and a namespace as well as implementing an interface, but none seem to work. My current idea is to declare the module in a separate file, but I can't get TS to recognize it. This is what I tried:
In myModule.d.ts:
interface MyModule {
[key: string]: any
}
declare module 'myModule' {
const myModule: MyModule
export = myModule
}
I also thought about including a triple slash reference in myFile.ts:
At the top of myFile.ts:
/// <reference path="./myModule.d.ts" />
import * as myModule from './myModule'
function doesSomething(input: string) {
return myModule[input]
}
However, this didn't resolve the issue at hand.