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.

Type "(string) => string" is incompatible with type "<T>(T) => T"

See original GitHub issue

I’m not sure i doing it correctly but here it is

type Fn = <T>(value: T) => T

let fn: Fn = (s:string) => '2'

try

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ikabirovcommented, May 6, 2020

@Merciful12 is’t incorrect case. Without generic in function test you can call function with any parameter:

type Fn = <T>(value: T) => T

function test(fn: Fn) {
  fn(true)
}

test((s: string) => s)
test((s: number) => s)
1reaction
srg-kostyrkocommented, May 6, 2020
type Fn<T> = (value: T) => T

function test<T>(fn: Fn<T>) {}

test((s: string) => s)
test((s: number) => s)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error using generic return type (incompatible types: cannot be ...
I have never used generics, so I'm a bit confused. $ javac Main.java Main.java:22: error: incompatible types: MyQueue cannot be converted to T...
Read more >
How to Handle the Incompatible Types Error in Java - Rollbar
The Java incompatible types error happens when a value assigned to a variable or returned by a method is incompatible with the one...
Read more >
Type 'T' is not assignable to type when Generic Anonymous ...
Type '(a: string) => string' is not assignable to type '<T>(a: T) => any'. Types of parameters 'a' and 'a' are incompatible. Type...
Read more >
Generic Types | Flow
If you want something to have a generic type, annotate it. Otherwise, Flow may infer a type that is less polymorphic than you...
Read more >
Documentation - Everyday Types - TypeScript
JavaScript has three very commonly used primitives: string , number , and ... When you don't specify a type, and TypeScript can't infer...
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