Nisha Patel
Problem
Learning typescript. Here is the code:
While calling the getNextId() function I've specified type type TodoI, then why I am supposed to extend the generic type?
Solution
Where you've defined getNextId, the generic type T argument has no properties, equivalent to any. Your function cannot know that T has an id property.
The simplest solution is to enforce the generic type T extends a type with an id property
FYI because the type passed to your function is inferred by the argument, you don't need to use generics when calling it
Suggested blog
>How to get the date and time and display it in a defineProps in Vuejs?
>Why logged user object is all strings in Vuejs and Laravel 10?
>What is meant by progressive framework?
>How can I replace this.$parent in composition API in Vuejs?
>How do I fix an invalid route component in the new VueJs Project?
>How to get all the rows selected in Vuejs?
>How to set up a dynamic grid based on flex or grid in Vuejs?