-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed as not planned
Closed as not planned
Copy link
Description
Reproduction
Steps to reproduce the bug
- Create an options or setup type store with a function in
actions
or one returned directly in the create function. - In a component, attempt to redefine the function property on the store object created by
useStore()
- Observe that these "action" functions are successfully overwritten at runtime, and that TypeScript does not complain at compile time.
For example, the following code (additional examples in the playground) will print "actually a bad function bwahahaha!"
when clicking on either of the buttons, instead of raising an error.
export const useSetupStore = defineStore('setup', () => {
const goodFunction = () => {
console.log('Good setup!');
};
return {
goodFunction,
};
});
export const useOptionsStore = defineStore('counter', {
actions: {
goodFunction() {
console.log('Good options!');
},
},
});
<script setup lang="ts">
import { useSetupStore, useOptionsStore } from './store.ts';
const setupStore = useSetupStore();
const optionsStore = useOptionsStore();
function badFunction() {
console.log('actually a bad function bwahahaha!');
}
setupStore.goodFunction = badFunction;
optionsStore.goodFunction = badFunction;
</script>
<template>
<button @click="setupStore.goodFunction()">Print Setup</button>
<button @click="optionsStore.goodFunction()">Print Options</button>
</template>
Expected behavior
- This would be a runtime error (proxy set handler or readonly property type) the way trying to overwrite a
getter
orcomputed
result does. - TypeScript would complain at compile time that the property is read only because of 1
Actual behavior
The property on the objects can be overwritten without issue, both at compile time and runtime.
Additional information
We encountered this as a bug in a non-contrived situation that took quite a while to track down.
Workaround
Removed, the workaround worked in some circumstances, but with refs and computeds, it would work at compile time with TypeScript and then result in a runtime error of TypeError: Cannot add property _getters, object is not extensible
.
Metadata
Metadata
Assignees
Labels
No labels