Javascript 如何在ImmutableJS记录类上正确使用Typescript接口?

Javascript 如何在ImmutableJS记录类上正确使用Typescript接口?,javascript,typescript,immutable.js,Javascript,Typescript,Immutable.js,我已经试着寻找如何正确地做到这一点,但我还没有找到令人满意的解决方案。我知道不可变的记录就是工厂。我的代码如下所示: import { Record } from 'immutable' interface ISessionDefaults { id: number | null, email: string, } interface ISession { id: number, email: string, } const defaults: ISessionDefaul

我已经试着寻找如何正确地做到这一点,但我还没有找到令人满意的解决方案。我知道不可变的记录就是工厂。我的代码如下所示:

import { Record } from 'immutable'

interface ISessionDefaults {
  id: number | null,
  email: string,
}

interface ISession {
  id: number,
  email: string,
}

const defaults: ISessionDefaults = {
  id: null,
  email: '',
}

class Session extends Record(defaults) implements ISession {
}
class Session extends Record(defaults) implements ISession {
  id: number
  email: string
}
我在类定义中遇到类型错误:

[tsserver 2420] [E] Class 'Session' incorrectly implements interface 'ISession'.
  Type 'Session' is missing the following properties from type 'ISession': id, email
class Session extends Record(defaults) implements ISession {
  id: number = 0
  email: string = ''
}
这是可以理解的,所以我扩展类定义如下:

import { Record } from 'immutable'

interface ISessionDefaults {
  id: number | null,
  email: string,
}

interface ISession {
  id: number,
  email: string,
}

const defaults: ISessionDefaults = {
  id: null,
  email: '',
}

class Session extends Record(defaults) implements ISession {
}
class Session extends Record(defaults) implements ISession {
  id: number
  email: string
}
此时,我遇到另一个类型错误:
[tsserver 2564][E]属性“id”没有初始值设定项,并且在构造函数中没有明确指定。

好的,现在是设置默认值的时候了。我更改了类定义:

[tsserver 2420] [E] Class 'Session' incorrectly implements interface 'ISession'.
  Type 'Session' is missing the following properties from type 'ISession': id, email
class Session extends Record(defaults) implements ISession {
  id: number = 0
  email: string = ''
}
但这实际上无法编译,因为我直接设置它。错误是
错误:无法在不可变记录上设置。

我想我可以定义
constructor
方法,但这意味着在设置了无效的初始值之后调用
super