Record inheritance in Typescript?
See original GitHub issueI were struggling with converting a model of ours to a Immutable.Map and found Record, which is perfect because we need to implement some functions.
But It doesn’t seem to be possible to use the example syntax i Typescript?
import Immutable = require("immutable");
class ABRecord extends Immutable.Record({ a: 1, b: 2 }) {
getAB() {
return this.a + this.b;
}
}
var myRecord = new ABRecord(b:3);
myRecord.getAB();// 4
Doesn’t compile at all, “The property ‘Record’ does not exist on value of type ‘Immutable’.” Any tips?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:8
- Comments:22
Top Results From Across the Web
Extend a `Record<string, string[]>` with a different type of ...
Record <string, string[]> means that the id property, if it exists, must be a string[] . You can't extend it with something that...
Read more >Inheritance in TypeScript - Manejando datos
TypeScript supports an inheritance model that is more aligned with other object-oriented languages. It's easy to work with and under the covers it's...
Read more >Immutable.js Records with Typescript Classes- Part 2
Supports inheritance; Like the existing Immutable.JS Record, you should be able to specify as many or as few properties as you'd like during ......
Read more >Handbook - Classes - TypeScript
This example shows the most basic inheritance feature: classes inherit properties and methods from base classes.
Read more >Instantiating Typescript classes with properties using inheritance
Instantiating Typescript classes with properties using inheritance · export class AbstractEntity<T> { constructor(protected partial: Partial<T>) { Object.assign( ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Why is this closed. The problem persists.
@leonuh @abergs I’ve created this library that has an interface called TypedRecord that extends from Immutable.Map and changes all return types to the generic provided type. It has a function called makeTypedFactory that will create Immutable.Record of the type you specify, it’s a just a utility but allows you to have typed Record all over the place and is a very very small library. https://github.com/rangle/typed-immutable-record