File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -225,8 +225,10 @@ export function defineReactive(
225225 * triggers change notification if the property doesn't
226226 * already exist.
227227 */
228+ export function set < T > ( array : T [ ] , key : number , value : T ) : T
229+ export function set < T > ( object : object , key : string | number , value : T ) : T
228230export function set (
229- target : Array < any > | Record < string , any > ,
231+ target : any [ ] | Record < string , any > ,
230232 key : any ,
231233 val : any
232234) : any {
@@ -279,7 +281,9 @@ export function set(
279281/**
280282 * Delete a property and trigger change if necessary.
281283 */
282- export function del ( target : Array < any > | Object , key : any ) {
284+ export function del < T > ( array : T [ ] , key : number ) : void
285+ export function del ( object : object , key : string | number ) : void
286+ export function del ( target : any [ ] | object , key : any ) {
283287 if ( __DEV__ && ( isUndef ( target ) || isPrimitive ( target ) ) ) {
284288 warn (
285289 `Cannot delete reactive property on undefined, null, or primitive value: ${ target } `
Original file line number Diff line number Diff line change @@ -72,5 +72,6 @@ export { h } from './h'
7272export { getCurrentInstance } from './currentInstance'
7373export { useSlots , useAttrs } from './apiSetup'
7474export { nextTick } from 'core/util/next-tick'
75+ export { set , del } from 'core/observer'
7576
7677export * from './apiLifecycle'
Original file line number Diff line number Diff line change @@ -11,7 +11,9 @@ import {
1111 shallowReactive ,
1212 readonly ,
1313 markRaw ,
14- shallowReadonly
14+ shallowReadonly ,
15+ set ,
16+ del
1517} from '../../index'
1618import { describe , expectType } from '../utils'
1719
@@ -371,3 +373,15 @@ describe('shallowReadonly ref unwrap', () => {
371373 expectType < Ref > ( r . count . n )
372374 r . count . n . value = 123
373375} )
376+
377+ describe ( 'set/del' , ( ) => {
378+ set ( { } , 1 , 'hi' )
379+ set ( [ ] , 1 , 'bye' )
380+ del ( { } , 'foo' )
381+ del ( [ ] , 1 )
382+
383+ // @ts -expect-error
384+ set ( { } , 1 )
385+ // @ts -expect-error
386+ del ( [ ] , 'fse' , 123 )
387+ } )
You can’t perform that action at this time.
0 commit comments