-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
what is the equal sign means in 'T extends Node = Node' #55
Labels
Comments
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 parameter
interface Foo<A> {
foo: A
}
// This interface provides a *default* when no type parameter is used
interface Bar<A = string> {
bar: A
}
// always needed
const foo: Foo<number> = { foo: 1 }
// will error about missing type parameter
const foo: Foo = { foo: 1 }
// When you want to specify something that's not the default
const nonDefaultBar: Bar<number> = { bar: 2 }
// use the default
const defaultBar: Bar = { bar: 'defaults to string' }
// This will error becase Bar<number> is not assignable to Bar
const errorBar: Bar = { bar: 2 } I hope this helps you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: