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.

Record inheritance in Typescript?

See original GitHub issue

I 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:closed
  • Created 9 years ago
  • Reactions:8
  • Comments:22

github_iconTop GitHub Comments

15reactions
paramsingh88commented, Jun 16, 2017

Why is this closed. The problem persists.

6reactions
danielfigueiredocommented, Jul 26, 2016

@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

Read more comments on GitHub >

github_iconTop 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 >

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