0

In my project I am using RadListView component for listing out some items and based on their documentation I made this implementation of it:

<page>
    <actionBar title="Goals" />
    <gridLayout rows="auto, *" backgroundColor="#3c495e">
        <gridLayout row={0} columns="*,auto" class="add-bar">
            <textField col={0} hint="Type new task..." bind:text={newGoal} bind:this={newGoalInput} />
            <button col={1} text="Add New Goal" on:tap={handleAddNewGoal} />
        </gridLayout>
        <radListView items={courseGoals} row={1} on:itemSwipeProgressStarted={onSwipeCellStarted}
            swipeActions={true} transition:fade={{duration: 1000 }} >
            <Template type={ListViewViewType.ItemView} let:item>
                <label class="p-15" text="{ item }" />
            </Template>
            <Template type={ListViewViewType.ItemSwipeView}>
                <gridLayout columns="*,auto">
                    <stackLayout id="delete-view" col={1} on:tap={handleGoalDelete} class="delete-view">
                        <image src="~/assets/delete.png" />
                    </stackLayout>
                </gridLayout>
            </Template>
        </radListView>
    </gridLayout>
</page>

The function that is being called looks this way:

const onSwipeCellStarted = (args: any) => {
    const deleteButtonWidth = args.object.getViewById('delete-view').getMeasuredWidth();
    args.data.swipeLimits.right = deleteButtonWidth;
    args.data.swipeLimits.threshold = deleteButtonWidth / 2;
}

Everything is working fine but there is a TypeScript error being thrown for the on:itemSwipeProgressStarted like so:

No overload matches this call.
  Overload 1 of 4, '(element: "radListView" | null | undefined, attrs: RadListViewAttributes): any', gave the following error.
    Argument of type '{ items: string[]; row: number; "on:itemSwipeProgressStarted": (args: any) => void; swipeActions: true; }' is not assignable to parameter of type 'TRadListViewAttributes'.
      Object literal may only specify known properties, and '"on:itemSwipeProgressStarted"' does not exist in type 'TRadListViewAttributes'.
  Overload 2 of 4, '(element: "radListView" | null | undefined, attrs: RadListViewAttributes): any', gave the following error.
    Argument of type '{ items: string[]; row: number; "on:itemSwipeProgressStarted": (args: any) => void; swipeActions: true; }' is not assignable to parameter of type 'TRadListViewAttributes'.
      Object literal may only specify known properties, and '"on:itemSwipeProgressStarted"' does not exist in type 'TRadListViewAttributes'.ts(2769)

Based on Svelte documentation I've created additional-svelte-typings.d.ts file in types folder which is in the root of the project and it's content looks like this:

declare namespace svelteHTML {        
    // enhance attributes
    interface HTMLAttributes<T> {
        // If you want to use on:beforeinstallprompt
        'on:itemSwipeProgressStarted'?: (args: any) => any;
    }

    interface TRadListViewAttributes<T> {
        // If you want to use on:beforeinstallprompt
        'on:itemSwipeProgressStarted'?: (args: any) => any;
    }        
}

My tsconfig.json file looks like so:

{
  "compilerOptions": {
    "strict": true,
    "target": "ES2020",
    "module": "esnext",
    "moduleResolution": "node",
    "lib": ["dom", "ESNext"],
    "sourceMap": true,
    "noEmitHelpers": true,
    "importHelpers": true,
    "baseUrl": ".",
    "paths": {
      "~/*": ["app/*"],
      "@/*": ["app/*"]
    },
    "typeRoots": ["node_modules/@types", "types"],
    "types": ["node"],
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipLibCheck": true
  },
  "include": ["app", "types"],
  "exclude": ["node_modules", "platforms"]
}

After all this the error still persists. How can I get rid of the error? Thanks.

f.bele
  • 207
  • 2
  • 13
  • One solution that I usually do is to import that type and assign it to the function. So something like `const onSwipeCellStarted: TRadListViewAttributes = (args: any) => {...}` – Joshua Q Jul 12 '23 at 19:45
  • @JoshuaQ thanks for a suggestion and is seems as a valid option, however the in this particular case this type is nowhere to be found so I cannot implement this solution. To be honest I can't even figure out from where TypeScript pulls the information about TRadListViewAttributes type. – f.bele Jul 13 '23 at 14:01
  • after digging around, I found the type `TRadListViewAttributes` in a GitHub repo: [svelte-native-nativescript-ui](https://github.com/halfnelson/svelte-native-nativescript-ui). Do you by any chance use this package? – Joshua Q Jul 13 '23 at 14:24
  • @JoshuaQ I have found it now too and tried to implement your solution but now I'm getting this error: ```Type '(args: any) => void' is not assignable to type 'RadListViewElement'.ts(2322) const onSwipeCellStarted: TRadListViewAttributes``` – f.bele Jul 13 '23 at 14:30
  • Try converting the function from an arrow function into a regular function. And if that doesn't work, try following this: [example](https://github.com/halfnelson/svelte-native-nativescript-ui/blob/1dd9382b4596f5d9ea308fecbc7f9254b76ffa95/demo/app/pages/ListViewPage.svelte#L162) – Joshua Q Jul 13 '23 at 14:40
  • Ok, after even more digging, it looks like RadListView doesn't even exist in the native-script core or the plugins anymore. The version svelte-native uses is [10.0.1](https://www.npmjs.com/package/nativescript-ui-listview/v/10.0.1) which was released 2 years ago. You might find luck in trying to fix all of these errors, but it just doesn't seem like the svelte-native hasn't even been updated to the recent svelte at all. – Joshua Q Jul 13 '23 at 14:52
  • NativeScript is now at version 8, and the docs doesn't even mention `RadListView` anymore meaning it got deprecated somewhere between 7 and 8. The new documentation for NativeScript also has an updated, better way of using NativeScript with Svelte, and I think that might be a better solution: https://docs.nativescript.org/tutorial/svelte | But if you do wish to continue using svelte-native, it would just be a real pain sorting all the errors and misaligned dependencies – Joshua Q Jul 13 '23 at 14:54
  • 1
    @JoshuaQ It seems as if v8 tutorial is not completely done yet. I found RadListView in the new documentation here: https://docs.nativescript.org/plugins/nativescript-ui/rad-list-view.html and is a part of NativeScript UI. I also checked the example you provided, the registering of the component is a bit different, but the rest is the same with my implementation. The only reason why is not throwing errors is because he is not using TypeScript at all, e.g. no lang="ts" property in – f.bele Jul 13 '23 at 16:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/254480/discussion-between-joshua-q-and-f-bele). – Joshua Q Jul 13 '23 at 16:08

0 Answers0