I have a Typescript file (colorTheme.ts) that looks like this:
export default (async (key) => {
console.log(key)
const themeImport = await import(`../build/theme/${key}/color.js`)
return themeImport
})()
And then I reference this function from a separate Typescript file like so:
import colorTheme from '../colorTheme'
colorTheme('test').then(color => {
// do stuff
})
However, I get an error:
TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Promise' has no compatible call signatures.
I've googled around and tried things like:
export default (async (key: string) => {
console.log(key)
const themeImport = await import(`../build/theme/${key}/color.js`)
return themeImport
})()
But to no avail. Typescript isn't my forte, it's a preexisting environment that I'm trying to work in. From what I understand I need to somehow setup types for the Promise maybe? But I'm not sure how to do that.
Update: Added a bit more fuller code sample for what I'm trying to do.
Promise. Because you are executing anasyncfunction and returns it (an async function returns a Promise). What are you trying to do ? I don't think that returning aPromiseis something viable importing a fileconst themeImport = await import(`../build/theme/${key}/color.js`)eeeuh I'm not sure it will ever work. Unlessimportis not a regular import, such code will be transpiled, so you won't be able to resolve the import at runtime on the compiled code. Also, the self invoking anonymous function will never get thekeyargument. Is there any reason to use an IIFE here?..async() => { const key = 'test' ...). It's the ability to be able to pass dynamic keys via the function call that seems to be giving me the problem.