Open maelp opened 9 months ago
@maelp can you hover over underlined red text and show error too, please)
thanks, will take a look on it)
BTW adding ":string" to term doesn't fix the bug for me (taking a look at your PR)
Yes, it just little issue so never mind, I will remove draft
status when resolve it)
https://github.com/radix-vue/shadcn-vue/issues/327#issuecomment-1935001998
@maelp To fix this issue you need to define Option
interface globally and pass it inside ComboboxRootProps
in Command.vue
, this will remove error inside your editor
Need to think about how to fix it globally, because issue is inside radix-vue components, when you don't define T
it takes default value of AcceptableValue
which is
export type AcceptableValue = string | number | boolean | object;
It's logical that Option
extends object
, but VS Code internal TS Server don't think so š
Will try to think with it, maybe need to fix radix-vue TS types š¤
@sadeghbarati maybe you will look and have some ideas, I will appreciate it ā¤ļø
Interesting... indeed I didn't know whether the issue was that the method is expecting any AcceptableValue and typescript is complaining that we are only handling the case where the filterFunction parameter is of type DataTableFacetedFilter['option']
and not the other cases that it thinks could happen (eg string, number, etc)... wondering if that's the issue? in that case it should be generic?
No, issue is that typescript don't think that our custom object for option is object
š
In my codebase I never use object
definition, because it not just Objects. Functions, Arrays is also type of object
is JS, think that maybe replace object
to type Record<string, any>
will help with this š¤
Is this fixed? I am still getting the type error on filterFunction
. Not sure how to get it right..
I'm also getting the same issue...
export type FilterItem = {
value: string;
label: string;
};
const onSift = (list: FilterItem[], term: string) => {
return list.filter(item => item.label.toLowerCase().includes(term.toLowerCase()));
};
Diagnostics:
1. Type '(list: FilterItem[], term: string) => globalThis.FilterItem[]' is not assignable to type '(val: string[] | number[] | false[] | true[] | Record<string, any>[], term: string) => string[] | number[] | false[] | true[] | Record<string, any>[]'. [2322]
@maelp To fix this issue you need to define
Option
interface globally and pass it insideComboboxRootProps
inCommand.vue
, this will remove error inside your editorNeed to think about how to fix it globally, because issue is inside radix-vue components, when you don't define
T
it takes default value ofAcceptableValue
which isexport type AcceptableValue = string | number | boolean | object;
It's logical that
Option
extendsobject
, but VS Code internal TS Server don't think so šWill try to think with it, maybe need to fix radix-vue TS types š¤
@sadeghbarati maybe you will look and have some ideas, I will appreciate it ā¤ļø
@romanhrynevych so is the other part of this solution commenting out modelValue
still correct, or was that for debugging? I dont want to break the component with unexpected side effects, but otherwise I get:
Diagnostics:
- Type 'string' is not assignable to type '(props: LooseRequired<ComboboxRootProps
& { class?: any; }>) => FilterItem | FilterItem[]'. [2322]
@maelp To fix this issue you need to define
Option
interface globally and pass it insideComboboxRootProps
inCommand.vue
, this will remove error inside your editorNeed to think about how to fix it globally, because issue is inside radix-vue components, when you don't define
T
it takes default value ofAcceptableValue
which isexport type AcceptableValue = string | number | boolean | object;
It's logical that
Option
extendsobject
, but VS Code internal TS Server don't think so šWill try to think with it, maybe need to fix radix-vue TS types š¤
@sadeghbarati maybe you will look and have some ideas, I will appreciate it ā¤ļø
This fixed the error for me.
In types/index.d.ts
export interface Option {
label: string;
value: string;
icon?: Component;
}
In Command.vue
import { Option } from "@/types";
const props = withDefaults(
defineProps<
ComboboxRootProps<Option> & { class?: HTMLAttributes["class"] }
>(),
{
open: true,
},
);
In FacetedFilter.vue (or wherever you define your filters)
interface DataTableFacetedFilter {
column: Column<any, any>;
title: string;
options: Option[];
default?: string | boolean;
search?: boolean;
}
<Command
:filter-function="
(list: DataTableFacetedFilter['options'], term: string) =>
list.filter((row) => row.label.toLowerCase()?.includes(term))
"
>
Reproduction
None
Describe the bug
When using the code from the Task table example DataTableFacetedFilter I have the following issue
I'm using the latest radix-vue, but it seems that filter-function first parameter should use "AcceptableValue[]" list, which contains string, number, object etc, but it doesn't typecheck for an arbitrary object for some reason(?)
System Info
Contributes