TypeScript中未定义文档

时间:2019-06-22 19:07:42

标签: typescript

我是TypeScript的入门者,正在尝试使用它构建一个简单的注册服务,但是不知何故出现了此错误

ReferenceError: document is not defined
    at Object.<anonymous> (C:\Users\hp\WebstormProjects\myhttp\dist\index.js:8:15)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

这是我的代码,我知道它很短而且不完整,但是我该如何处理文档呢?

 class User  {
        name:string;
        surname:string;
        // constructor
        constructor(name:string , surname:string) {
            this.name = name;
            this.surname = surname;
        }
    }

    let userArray: User[] = [];

    let addUser = document.getElementById("add-user-button").addEventListener("click", () => {
        let userName = document.getElementById("user-name-val").nodeValue;
        let userSurname = document.getElementById("user-surname-val").nodeValue;
        userArray.push(new User(userName,userSurname));

    });

0 个答案:

没有答案