vue-lynx / shallowReadonly

Function: shallowReadonly()

function shallowReadonly<T>(target): Readonly<T>

Shallow version of readonly.

Unlike readonly, there is no deep conversion: only root-level properties are made readonly. Property values are stored and exposed as-is - this also means properties with ref values will not be automatically unwrapped.

Type Parameters

Type Parameter
T extends object

Parameters

ParameterTypeDescription
targetTThe source object.

Returns

Readonly<T>

Example

const state = shallowReadonly({
  foo: 1,
  nested: {
    bar: 2
  }
})

// mutating state's own properties will fail
state.foo++

// ...but works on nested objects
isReadonly(state.nested) // false

// works
state.nested.bar++

See

https://vuejs.org/api/reactivity-advanced.html#shallowreadonly

Defined in

node_modules/.pnpm/@vue+reactivity@3.5.30/node_modules/@vue/reactivity/dist/reactivity.d.ts:145