You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
excuse me sir ,I am a rookie,when I red your code as follows. I have no idea what is 'T extends Node = Node' . I Look it up in the document of typescript about generic, but the question about remain unanswered,Can you give me some idea to inspire me
Hello @yyf1994gggg! In TypeScript, I believe they are called "type parameter defaults" - see: microsoft/TypeScript#2175
I'll try to explain how this works in practice
// This interface *requires* a type parameterinterfaceFoo<A>{foo: A}// This interface provides a *default* when no type parameter is usedinterfaceBar<A=string>{bar: A}// always neededconstfoo: Foo<number>={foo: 1}// will error about missing type parameterconstfoo: Foo={foo: 1}// When you want to specify something that's not the defaultconstnonDefaultBar: Bar<number>={bar: 2}// use the defaultconstdefaultBar: Bar={bar: 'defaults to string'}// This will error becase Bar<number> is not assignable to BarconsterrorBar: Bar={bar: 2}
excuse me sir ,I am a rookie,when I red your code as follows. I have no idea what is 'T extends Node = Node' . I Look it up in the document of typescript about generic, but the question about remain unanswered,Can you give me some idea to inspire me
The text was updated successfully, but these errors were encountered: