Proper use of React.Events in TypeScript 2.0?

I have an application using React and TypeScript. I recently updated type definitions to use the npm namespace @typesto save them in my folder node_modules.

Previously, when working with DOM events, such a method signature met type definitions:

public updateValue(e: React.FormEvent): void {

Now, however, I get compiler errors:

(46,25): error TS2314: Generic type 'FormEvent<T>' requires 1 type argument(s).  

And after searching the reaction type definitions folder, it really takes on a general character:

interface FormEvent<T> extends SyntheticEvent<T> {
}

My question mainly consists of what is used for this general, how to use it and what advantages does it add? I could just change my method to:

public updateValue(e: React.FormEvent<any>): void {

And this will satisfy the type definition requirement. But what is the intended use case?

+4
1

response.d.ts, , , HTMLElement, currentTarget . Mozilla Docs , .

[currentTarget: EventTarget & T;]

T

interface ReactHTMLElement<T extends HTMLElement> extends DOMElement<HTMLAttributes<T>, T> {

, , , T . , - , (, src .. HTMLImageElement) currentTarget. , - lib.d.ts .

, , - .

+3

Source: https://habr.com/ru/post/1657942/


All Articles