question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pull out property of computed value: TypeScript Error

See original GitHub issue

interface IBook { id: string tittle: string ... }

const model = { currentBook?: Computed<Books, IBook | undefined, IBook>; }

currentBook: computed((state) => state.books.find((book) => book.id === state.id))

const Component => { currentBook?.id // **TypeScript Error Property 'id' does not exist on type 'Computed '.** currentBook?.title // **TypeScript Error Property 'title' does not exist on type 'Computed '.** currentBook?.result?.id // undefined }

@ts-ignore const { publisher, synopsis, title, author, pageCount, id, coverImageUrl } = currentBook; // WORKS

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Standupiccommented, Apr 17, 2022

@jacekk It works properly, thanks for your time.

 const currentBook = useStoreState((state: StoreModel) => state.books.currentBook);
  if (currentBook && currentBook.result) {
  const { publisher, synopsis, title, author, pageCount, id, coverImageUrl } = currentBook.result;
1reaction
jacekkcommented, Apr 17, 2022

@Standupic I can see the property --> https://github.com/Standupic/Book-discovery/blob/main/src/types/books.ts#L8 😉 So just add a check in your Book component.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VueJS 2 + TypeScript: computed value does not detect ...
For this reason, you may need to annotate the return type on methods like render and those in computed. Therefore, try this: computed:...
Read more >
Computed properties cannot correctly infer even simple return ...
Yarn will load webpack and attempt to build the project, at which point the typescript compilation will fail on the ErrorReproduction.vue file.
Read more >
Documentation - TypeScript 2.9
Number-like properties of an object type are those declared using a numeric literal or computed property name of a numeric literal type.
Read more >
3 Anti-Patterns to avoid in Vue.js - Binarcode
What actually happens in this case is that, our computed property get's “re-computed” every time in an infinite loop. We change the discount,...
Read more >
TypeScript with Composition API - Vue.js
However, it is usually more straightforward to define props with pure types ... double = computed(() => count.value * 2) // => TS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found