Skip to content

Instantly share code, notes, and snippets.

@Sammons
Created October 23, 2018 04:23
Show Gist options
  • Save Sammons/3dc5110dc7d7611ac6a1fbfec441fe34 to your computer and use it in GitHub Desktop.
Save Sammons/3dc5110dc7d7611ac6a1fbfec441fe34 to your computer and use it in GitHub Desktop.
addNode<NodeName extends string, ReturnType extends AddNodeName<this, NodeName>>(
 nodeName: Exclude<NodeName, NodeNames>,
 builderCb: (b: NodeBuilder<this>) => NodeBuilder<this>
 ): ReturnType {
 // Yes you can totally infer the result type of builderCb and stick it in a RootBuilder generic param,
 // but I am not covering that here. ask if you want samples :)
 const result = builderCb(); 
 return this as RootBuilder as ReturnType
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment