rpc-anywhere icon indicating copy to clipboard operation
rpc-anywhere copied to clipboard

Property 'addMessageListener' does not exist on type 'RPC<IframeSchema, ParentSchema>'

Open phanmn opened this issue 1 year ago • 5 comments

In which versions of the package (and relevant enviroment tools such as Node.js) have you observed the bug?

1.7.0

What steps will reproduce the bug?

Follow README

What behavior did you expect?

No ts error

What actually happened?

Property 'addMessageListener' does not exist on type 'RPC<IframeSchema, ParentSchema>'

Workaround

No response

Proposed fix

No response

Other remarks

No response

Contribution

  • [ ] I would like to try to contribute a fix

phanmn avatar Jun 11 '24 08:06 phanmn

I can't reproduce this issue. Did you copy the iframe example as-is? Here's a TypeScript playground I created that shows it all working: https://tsplay.dev/m3dpyW

DaniGuardiola avatar Jun 11 '24 10:06 DaniGuardiola

This might be relevant to you: docs

The schema types affect the rpc instance types. If the remote schema type doesn't declare any messages it can send, then your local rpc instance type won't have an addMessageListener method, since there's no message to listen to. The README example does have it though, so I'm not sure what's going on in your case.

It would easier for me to debug if you could share a more complete reproduction of the issue, using the TypeScript playground or a sandbox service like Stackblitz

DaniGuardiola avatar Jun 11 '24 10:06 DaniGuardiola

Thanks @DaniGuardiola , I will try to give you reproduction soon

phanmn avatar Jun 11 '24 10:06 phanmn

I found the reason, because the tsconfig.json

My original config (from nuxt3)

{
  // https://nuxt.com/docs/guide/concepts/typescript
  "extends": "./.nuxt/tsconfig.json",
  "vueCompilerOptions": {
    "plugins": ["@vue/language-plugin-pug"]
  },
  "compilerOptions": {
    "sourceMap": true,
    "strict": false,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "types": []
  }
}

Missing config

"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"declaration": true,
"target": "ES2017",
"module": "ESNext"

phanmn avatar Jun 24 '24 04:06 phanmn

Interesting. Could you find the specific config value that makes it break/work? It'd help to get a narrowed-down version so I can investigate.

DaniGuardiola avatar Jun 24 '24 22:06 DaniGuardiola