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

chore: improve the types for $set and $delete #13047

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/core/observer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ export function defineReactive(
* already exist.
*/
export function set<T>(array: T[], key: number, value: T): T
export function set<T>(object: object, key: string | number, value: T): T
export function set<T extends Record<keyof any, any>, K extends keyof T>(
object: T,
key: K,
value: T[K]
): T
export function set(
target: any[] | Record<string, any>,
key: any,
Expand Down Expand Up @@ -278,7 +282,10 @@ export function set(
* Delete a property and trigger change if necessary.
*/
export function del<T>(array: T[], key: number): void
export function del(object: object, key: string | number): void
export function del<T extends Record<keyof any, any>, K extends keyof T>(
object: T,
key: K
): void
export function del(target: any[] | object, key: any) {
if (__DEV__ && (isUndef(target) || isPrimitive(target))) {
warn(
Expand Down