description
give an example of jQuery
declaration file
interface JQueryStatic {
// ...
<TElement extends Element = HTMLElement>(selector: JQuery.Selector, context?: Element | Document | JQuery): JQuery<TElement>;
}
if it is < TElement extends Element > (selector: JQuery.Selector, context?: Element | Document | JQuery): JQuery < TElement >
, I understand that it probably means: "you can pass a generic parameter TElement, and TElement needs to satisfy the constraint of Element type"
question
-
< TElement extends Element = HTMLElement >
, what is the meaning of= HTMLElement
here? -
the
=
assignment here looks like the default value of a function parameter, does it represent the default value of a generic type? however, according to the official Chestnut, type inference automatically determines the type of confirmation T, which should not require the default value of generics, right?function identity<T>(arg: T): T { return arg; } let output = identity<string>("myString"); // type of output will be "string" // -- T let output2 = identity("myString"); // type of output will be "string"