question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does Typewriter support inheritance?

public class Report {}

public class SpecificReport : Report {}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
sigVincecommented, Apr 3, 2017

Here’s how to import all needed references (for complex objects and inheritance)

string Inherit(Class c)
{
if (c.BaseClass!=null)
	return " extends " + c.BaseClass.ToString();
  else
	 return  "";
}

string Imports(Class c){
  List<string> neededImports = c.Properties
	.Where(p => !p.Type.IsPrimitive)
	.Select(p => "import { " + p.Type.Name.TrimEnd('[',']') + " } from './" + p.Type.Name.TrimEnd('[',']') + "';").ToList();
  if (c.BaseClass != null) { 
	neededImports.Add("import { " + c.BaseClass.Name +" } from './" + c.BaseClass.Name + "';");
  }
  return String.Join("\n", neededImports.Distinct());
}
$Classes(*DTO)[$Imports

export interface $Name$TypeParameters$Inherit {

$Properties[    $name: $Type;
]}
]
4reactions
coolkevcommented, Mar 16, 2016

Put a code block at the top of your template

${

    string ClassNameWithExtends(Class c) {
        return c.Name +  (c.BaseClass!=null ?  " extends " + c.BaseClass.Name : "");
    }


}

Then you can call it like so:

$Classes(...)[
class $ClassNameWithExtends {

}]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Inheritance (2020)
The patriarch of a wealthy and powerful family suddenly passes away, leaving his daughter with a shocking secret inheritance that threatens to unravel...
Read more >
Inheritance (2020 film)
Inheritance is a 2020 American thriller film directed by Vaughn Stein from a screenplay by Matthew Kennedy. The film stars Lily Collins, Simon...
Read more >
Inheritance Definition & Meaning
noun ; a · the act of inheriting property ; b · the reception of genetic qualities by transmission from parent to offspring...
Read more >
Inheritance: Definition, How It Works, and Taxes
An inheritance may contain cash, investments such as stocks or bonds, and other assets such as jewelry, automobiles, art, antiques, and real estate....
Read more >
Watch Inheritance
When Lauren's wealthy father dies and leaves her the keys to a hidden bunker on their estate, what she finds could destroy her...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found