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.

Extending structs

See original GitHub issue

Is there an easy way to extend struct objects? I read through the documentation and couldn’t figure out how to do it. I’d like to write something like this:

class A {
    someProp = "";
    static validationStruct = object({ someProp: string() });
}

class B extends A {
    anotherProp = 0;
    static validationStruct = A.validationStruct.extend({ anotherProp: number() });
}

const b = new B();
assert(b, B.validationStruct)

Maybe this is an anti-pattern or there’s a better way. Would love any insight you can offer. Thanks.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ianstormtaylorcommented, Nov 20, 2020

@xiaoyu-tamu hoping to merge it imminently.

1reaction
SteveDeWaldcommented, Aug 25, 2020

Hey @SteveDeWald , did you get anything on this?

I ended up specifying the extended properties directly, e.g.:

class A {
    someProp = "";
    static validationStructAttrs = { someProp: string() };
}

class B extends A {
    anotherProp = 0;
    static validationStruct = object({ 
        ...A.validationStructAttrs,
        anotherProp: number()
    });
}

Not very elegant, but it works fine for my purposes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I 'extend' a struct in C? - Stack Overflow
because I have an 'object' struct which heads all the structs in the project). I could simply embed the struct like you mention...
Read more >
Tip 63: Seamlessly extend C structures - Modeling with Data
The syntax: include another struct in the declaration of the new structure. All of the elements of the other structure are included in...
Read more >
Extending struct with another : r/learnrust - Reddit
lets say i have struct struct Base { w: u64, h: u64, } which i want to extend with other structs struct Extension1...
Read more >
Extending Structure Functionality - ALM Works Help Center
You can extend Structure add-on's functionality with your own add-on by using one of the available extension points. Creating a New Column Type...
Read more >
Extension Methods for Structs - YouTube
Value types pass by value and reference types pass by reference. But interfaces are implemented by both value and reference types.
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