相关疑难解决方法(0)

为什么我收到错误"对象文字可能只指定已知属性"?

我刚刚从TypeScript 1.5升级到最新版本,我在代码中看到错误:

interface Options {
   /* ... others ... */
   callbackOnLocationHash?: boolean;
}

function f(opts: Options) { /* ... */ }

//  Error: Object literal may only specify known properties,
//     and 'callbackOnLoactionHash'does not exist in type 'Options'.
f( { callbackOnLoactionHash: false });
Run Code Online (Sandbox Code Playgroud)

代码看起来很好.怎么了?

(另类宇宙版:我认识到错字,我真的很想写那个.我该怎么做才能删除错误?)

typescript

52
推荐指数
1
解决办法
6万
查看次数

类型错误:无法读取未定义的属性“id” - Angular 8 测试

尝试在我的 angular 8 应用程序中执行单元测试时,我收到 TypeError: cannot read property 'id' of undefined 。

这是我的模板

这是我的组件

import {Component, EventEmitter, Input, OnInit} from '@angular/core';
import { Student } from '@app/app-types';

@Component({
...... saved some typing
})

export class StudentComponent implements OnInit {
@Input() student: Student;
refreshForm: EventEmitter<any>;

constructor(){}

ngOnInit(){
  this.refreshForm = new EventEmitter();
  }
}
Run Code Online (Sandbox Code Playgroud)

这是单元测试

import {async, ComponentFixture, TestBed } from '@angular/core/testing';
import {StudentComponet} from './student-component';

describe('StudentComponet', () => {
  let component: StudentComponent;
  let fixture: ComponentFixture<StudentComponent>;
  
  beforeEach(async(() => {
  TestBed.configureTestingModule({
    declarations: …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing angular

3
推荐指数
1
解决办法
2962
查看次数

标签 统计

angular ×1

javascript ×1

typescript ×1

unit-testing ×1