emscripten-core / emscripten-core/emscripten
Error "This expression is not callable" with embind-emit-tsd
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Please include the following in your bug report:
**Version of emscripten/emsdk:**
3.1.47
**Failing command line in full:**
Given a script similar to :
```
#!/bin/sh
set -e
set -v
cat << EOF > mywrapper.cpp
#include
#include
#include
class MyWrapper
{
public:
explicit MyWrapper();
~MyWrapper();
int getNum();
};
#include
#include
int main(int argc, char** argv)
{
return 0;
}
MyWrapper::MyWrapper()
{
}
MyWrapper::~MyWrapper()
{
}
int MyWrapper::getNum()
{
return 42;
}
// clang-format off
EMSCRIPTEN_BINDINGS(my_wrapper)
{
emscripten::class_("MyWrapper")
.constructor()
.function("getNum", &MyWrapper::getNum)
;
}
// clang-format on
EOF
cat << EOF > main.ts
import MyWrapperModule from './myWrapperModule.js';
MyWrapperModule().then(module => {
let obj = new module.MyWrapper();
// TODO: Typescript should tell me a number is not a string
let result : string = obj.getNum();
console.log("Loaded module", result);
});
EOF
cat << EOF > tsconfig.json
{
"ts-node": {
"files": true
},
"files": [
"myWrapper.d.ts"
]
}
EOF
em++ --embind-emit-tsd=myWrapper.d.ts -O2 -g -o mywrapper.cpp.o -c mywrapper.cpp
em++ --embind-emit-tsd=myWrapper.d.ts -O2 -g -sWASM=1 \
-sMODULARIZE=1 -sEXPORT_NAME=MyWrapperModule \
--minify=0 --bind \
-sENVIRONMENT=node mywrapper.cpp.o -o myWrapperModule.js
npx ts-node -P tsconfig.json main.ts
```
I think the generated typescript defintions file has the wrong content. In my actual build, I get an error like
```
Error: myfile.ts:28:9 - error TS2349: This expression is not callable.
Type 'typeof import(".../myWrapperModule")' has no call signatures.
28 MyWrapperModule()
~~~~~~~~~~~~~~~~~~~~~~
```
but I don't know how to make the minimal testcase run the js file.
Contributor guide
Assessment
This issue has not been assessed yet.