My vue code looks like this:
const chosenWallet = computed({
get() {
return return wallet.value ? wallet.value!.name : null;
},
set(newVal: WalletName) {}
}
An error is being thrown with the following message:
TS2769: No overload matches this call.
Overload 1 of 2, '(getter: ComputedGetter<unknown>, debugOptions?: DebuggerOptions | undefined): ComputedRef<unknown>', gave the following error.
Argument of type '{ get(): WalletName | null; set(newVal: WalletName): void; }' is not assignable to parameter of type 'ComputedGetter<unknown>'.
Object literal may only specify known properties, and 'get' does not exist in type 'ComputedGetter<unknown>'.
Overload 2 of 2, '(options: WritableComputedOptions<WalletName>, debugOptions?: DebuggerOptions | undefined): WritableComputedRef<WalletName>', gave the following error.
Type '() => WalletName | null' is not assignable to type 'ComputedGetter<WalletName>'.
Type 'WalletName | null' is not assignable to type 'WalletName'.
Type 'null' is not assignable to type 'WalletName'.
44 | const { wallet, setWallet } = useWallet();
45 | const chosenWallet = computed({
> 46 | get() {
| ^^^
47 | return wallet.value ? wallet.value!.name : null;
48 | },
49 | set(newVal: WalletName) {
I am struggling to understand the issue, but it seems Vue's computed()
function expects the return value to be strictly WalletName
, while my getter returns WalletName | null
.
I attempted to add types in various places, but the error persists. How can I resolve this?