Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Props throw TypeError: Cannot redefine property: xxx (with workaround) #81

Open
whitetrefoil opened this issue Nov 7, 2022 · 2 comments

Comments

@whitetrefoil
Copy link
Contributor

I just got this error during upgrading of legacy project.

Post here just In case 😹 anyone else meets this problem during upgrading.

Workaround

Set "target" of TypeScript to "ES2021" or lower.

Analysis

TS changes the transpiled JS code of class properties when targeting ES2022 or higher (not sure started from what version of TS, just tested the latest v4.8.4).

// for a prop
@Prop disabled = p({type: Boolean, default: false})

// ES2021 or lower
_this.disabled=Object(av_ts__WEBPACK_IMPORTED_MODULE_1__["p"])({type:Boolean,default:false});

// ES2022 or higher
_defineProperty(_assertThisInitialized(_this),"disabled",Object(av_ts__WEBPACK_IMPORTED_MODULE_1__["p"])({type:Boolean,default:false}));

Since collectData in core.ts also uses defineProperty, this change causes redefine property errors.

@HerringtonDarkholme
Copy link
Owner

Thanks for the debugging tip! decorator is too complex to be used :(

@whitetrefoil
Copy link
Contributor Author

Anyway the workaround works. Since Vue 3 has been release for long, I guess only aged projects use this now, targeting ES2021 should be totally enough. 😹

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

No branches or pull requests

2 participants