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) Generic is not picked up properly

See original GitHub issue

Describe the issue

Which language seems to have the issue?

typescript, no auto-detection

Are you using highlight or highlightAuto? I don’t know what this means.

Sample Code to Reproduce

I tried to reproduce the issue using your jsfiddle, but the typescript generic is not even displaying there ¯\(ツ)/¯.
~~https://jsfiddle.net/x3nzp2rf/~~
updated: https://jsfiddle.net/sm706vyd/2/

I have this code on StackOverflow.

meta: https://meta.stackoverflow.com/questions/420116/typescript-syntax-highlight-with-generic-not-picked-up-properly

first observed issue here: https://stackoverflow.com/questions/72794594/typescript-interface-merging-to-make-an-external-libs-interface-property-more-s/73527814#73527814

```lang-ts
import { useWeb3React as useWeb3React_ } from '@web3-react/core'

export const useWeb3React: <T = any>(key?: string) => Modify<
  ReturnType<typeof useWeb3React_<T>>,
  { chainId: SupportedChainIds }
> = useWeb3React_ as any

declare global {
  type SupportedChainIds = 1 | 4
}
```

Which produces incorrect syntax highlight

import { useWeb3React as useWeb3React_ } from '@web3-react/core'

export const useWeb3React: <T = any>(key?: string) => Modify<
  ReturnType<typeof useWeb3React_<T>>,
  { chainId: SupportedChainIds }
> = useWeb3React_ as any

declare global {
  type SupportedChainIds = 1 | 4
}

After a tweak I achieve correct syntax highlight

import { useWeb3React as useWeb3React_ } from '@web3-react/core'

export const useWeb3React: < T = any >(key?: string) => Modify<
  ReturnType<typeof useWeb3React_<T>>,
  { chainId: SupportedChainIds }
> = useWeb3React_ as any

declare global {
  type SupportedChainIds = 1 | 4
}

This is the tweak:

- export const useWeb3React: <T = any>(key?: string) => Modify<
+ export const useWeb3React: < T = any >(key?: string) => Modify<

Expected behavior

(without the spaces around < T = any > - correct is: <T = any>)

Actual behavior

Additional context

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
joshgoebelcommented, Sep 1, 2022

As you see from the other issue it seems like if we add the = case that I think now we’re covering all the bases?

1reaction
joshgoebelcommented, Aug 29, 2022

#3604 might be a reasonable fix. Thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generic type not recognised properly by Typescript
I just checked the Object.entries() typing: /** * Returns an array of key/values of the enumerable properties of an object * @param o...
Read more >
Generic Extended Types not inferring Correctly #48741 - GitHub
This is a common unsoundness caused by mutability. To not break type soundness, mutable properties, and mutable arrays, must be invariant.
Read more >
How To Use Generics in TypeScript - DigitalOcean
TypeScript fully supports generics as a way to introduce type-safety into components that accept arguments and return values whose type will be ...
Read more >
TypeScript Generics — Let's Get Real | by Chris D'Ascoli
This is the true story of TypeScript generics hand picked to be described in layman terms, why one would use them, and show...
Read more >
Understanding TypeScript Generics - Smashing Magazine
An introduction to the utilization of Generics in TypeScript with examples grounded in real-world use cases, such as collections, ...
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