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.

Typescript intellisense

See original GitHub issue

Hiya folks!

Tried to use this in a project and if I try and add a product using addItem and then try to map over the items afterwards, Typescript doesn’t seem to understand any of the other props that I passed in with my object. It is only doing intellisense on the Item

interface Item {
  id: string;
  price: number;
  quantity?: number;
  itemTotal?: number;
  [key: string]: any;
}

Seems to fully ignore [key: string]: any;

Is this expected behaviour?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
AaronLaytoncommented, Jun 23, 2021

I realise after this that with TypeScript you can have generic components, so could be worth making a Provider that accepts a generic

type MyBasketProduct {
    legLength: number
}

<CartProvider<MyBasketProduct> id="basket" onItemAdd={(item) => console.log(item)}>
    <MainApp />
</CartProvider>
1reaction
Skidragoncommented, Jul 2, 2021

To add onto this, I would like this to be updated as well:

interface CartProviderState extends InitialState {
    addItem: (item: Item, quantity?: number) => void;
    removeItem: (id: Item["id"]) => void;
    updateItem: (id: Item["id"], payload: object) => void;
    updateItemQuantity: (id: Item["id"], quantity: number) => void;
    emptyCart: () => void;
    getItem: (id: Item["id"]) => any | undefined;
    inCart: (id: Item["id"]) => boolean;
}

There is no setItems: (items: Item[]) => void; in here. I’ve added PR for this fix, let me know if its good to go because its my first ever code fix on open source.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript Programming with Visual Studio Code
IntelliSense shows you intelligent code completion, hover information, and signature help so that you can write code more quickly and correctly. TypeScript ......
Read more >
VS Code: enable javascript intellisense in typescript project
Is there a way to enable intellisense for Javascript files in a Typescript project? If I import a function from a javascript package...
Read more >
JavaScript and TypeScript Intellisense - XrmToolkit.com
XrmToolkit provides both JavaScript and TypeScript files that allow you to have all the intellisense features in Visual Studio for your CRM forms....
Read more >
JavaScript IntelliSense - Visual Studio - Microsoft Learn
IntelliSense based on TypeScript declaration files ... Because JavaScript and TypeScript are now based on the same language service, they are able ...
Read more >
Is there any way to activate IntelliSense for TypeScript files in ...
as an in-browser code editor, can github.dev activate the sophisticated kind of IntelliSense for .ts files that the desktop version of ...
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