typescript 错误 : Cannot read property X of undefined

标签 typescript

我创建了一个类 Meetings 的实例:

export var meeting: Meetings; //create a meeting instance of Meeting class present into meeting.ts

当我在 Meetings 类上调用名为“meetForMe()”的函数时:

var myMeeting = meeting.meetForMe(email);

我收到这个错误:

Cannot read property 'meetForMe' of undefined

我以这种方式宣布类(class) session :

export class Meetings{....}

最佳答案

对象应该在使用前被创建:

export var meeting = new Meetings();

在您的代码中,您只需声明一个“ session ”类型的变量。

关于 typescript 错误 : Cannot read property X of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41381611/

相关文章:

typescript - 使用 typescript 类验证器进行(嵌套)索引签名

typescript - 带有 ts-loader 的 webpack 线程加载器

typescript - 构建推断对象会起作用,直到它不起作用为止

javascript - 在 Angular 2/Typescript 中使用 IScroll

typescript - Typescript --allowJs 如何工作?

javascript - 无法读取未定义的属性 'status' - 函数实际运行之前出错?

angular - 具有父/子关系的 Angular 组件中的通用类型定义

javascript - typescript 中的绑定(bind)函数和 this

javascript - 如何在 Sublime 中不将 'do'/'package' 等对象键高亮为关键字?

接口(interface)的 Typescript 声明问题