Skip to content

fix: remove redundant _capnp declaration in Struct#170

Open
mrbbot wants to merge 1 commit intojdiaz5513:masterfrom
mrbbot:struct-type-error
Open

fix: remove redundant _capnp declaration in Struct#170
mrbbot wants to merge 1 commit intojdiaz5513:masterfrom
mrbbot:struct-type-error

Conversation

@mrbbot
Copy link

@mrbbot mrbbot commented Oct 17, 2022

Hey! 👋 Thanks for building this package! Super useful! 🙂 I hit this error when trying to type check a project:

node_modules/capnp-ts/src/serialization/pointers/struct.ts:110:12 - error TS2612: Property '_capnp' will overwrite the base property in 'Pointer'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.

110   readonly _capnp!: _Struct;
               ~~~~~~


Found 1 error in node_modules/capnp-ts/src/serialization/pointers/struct.ts:110

Removing the redundant declaration seems to fix this. 👍

@ttiurani
Copy link

ttiurani commented Feb 21, 2023

Thanks for this PR, this is the only way to actually get deserialization to work at all. Without this, the published 0.7.0 gives the runtime error Cannot set properties of undefined (setting 'compositeIndex') (I'm packaging with Vite).

That points to the second line in this javascript constructor:

constructor(segment, byteOffset, depthLimit = MAX_DEPTH, compositeIndex) {
    super(segment, byteOffset, depthLimit);
    this._capnp.compositeIndex = compositeIndex;
    this._capnp.compositeList = compositeIndex !== void 0;
}

If I use the this PRs capnp-ts in package.json:

        "capnp-ts": "https://gitpkg.now.sh/mrbbot/capnp-ts/packages/capnp-ts?struct-type-error"

the problem goes away. 0.7.0 used to work fine, so I suspect this is a problem with a new version of Typescript or node or Vite?

Would be great to get this merged to that capnp-ts in npmjs would actually be usable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants