Zygro
Zygro

Reputation: 7119

How to type a generic variable and function that uses the same type?

I'd like something like

interface propType {
  value: T
  action: (value: T) => void
}

Where T is anything, but it has to be same for both value and action. Typing them as any doesn't work because it would allow a type mismatch.

Upvotes: 0

Views: 28

Answers (1)

user12251171
user12251171

Reputation:

You were almost there:

interface propType<T> {
  value: T
  action: (value: T) => void
}

Upvotes: 4

Related Questions