嗨,我尝试过在角11中做反应形式的验证,但是它在终端中显示了跟随错误。
error TS2531对象可能为空.
我的signup.component.ts代码
import {FormGroup, FormControl, Validators} from '@angular/forms';
form = new FormGroup({
firstName: new FormControl('',Validators.required)
})
get f()
{
return this.form.controls;
嘿,我是第一次输入脚本,并且在函数中得到一个对象可能是空错误。该函数应该接受两个表示数字的LinkedLists (列表中的每个数字都是它自己的节点),然后将它们相加,返回一个不同的链表。有人能给我解释一下为什么会出现这个错误吗? 这就是错误 Line 33: Char 12: error TS2531: Object is possibly 'null'.
Line 33: Char 35: error TS2531: Object is possibly 'null'.
Line 35: Char 24: error TS2531: Object is p
当我在tsconfig.json中使用strictNullChecks: true并使用isNull进行null检查时,编译器抛出错误TS2531: Object is possibly 'null'。isNull摆脱了VsCode中的错误,但当我试图构建和运行我的Angular应用程序时,编译器仍然会报错。如果我使用=== null进行空检查,没有错误。
有没有一种方法可以告诉编译器将isNull视为有效的空检查?
import { isNull } from "util"; // from @types/node
...
public ru
第一次将Typescript添加到我的项目中。 在一个地方,我曾经使用window.document.getElementById访问过一些东西。它给出了这个错误。 Type error: Object is possibly 'null'. TS2531 我在网上搜索,但找不到最好的解决方案。窗口不能为空。如何修复此错误?请帮帮忙。
我用这段代码创建了一个新的角库项目。
/**
* Extract the path from the URL.
*
* @param url The URL to extract the path from
*/
export function urlPath(url: string): string {
return url!.match(/.*?(?=[?;#]|$)/)[0];
}
即使我有一个非空断言操作符!附加了url,我仍然会看到林特错误,说明url可能为null ( Object可能是‘null’..ts(2531 ) )。
有什么想法吗?
这是构建的输出:
✖
在JavaScript,中
function f() { return /* either a number or null */; }
let b = f() < 0; // false if f() returns null
但是在TypeScript中,如果为f提供类型注释并启用严格的空检查,则会得到编译器错误Object is possibly 'null'。
function f(): number | null { return /* either a number or null */; }
let b = f() < 0; // <-- e
我试图让这个发挥作用:
// Listens for new log added to /log/:pushId/original and creates an
// uppercase version of the log to /log/:pushId/uppercase
exports.db_uppercaseLog=functions.database
.ref('/log/{pushId}/original')
.onCreate((snapshot)=>{
// Grab the current value of what was written to t
我有一个必须启用虚拟化的列表框。然后我有一个地图,上面绘制了项目,需要有让用户点击它们的功能。当他们单击某个项目时,我需要将该项目显示在列表框中。
问题是虚拟化。当我尝试获取容器时,它返回null,这是有意义的,但是正确的做法是什么呢?我已经尝试了一些东西,比如UpdateLayout(),但我还没有找到答案。有什么想法吗?
var container = lstItems.ItemContainerGenerator.ContainerFromItem(clickedItem);
if (container != null)
{
var exp = container.Descen
由于某种原因,类型记录无法确定代码在运行时不可访问,并显示无法发生的错误。
我有这样的代码:
class ApplicationError extends Error {}
class Company {
public ownerId: number = 123;
}
// This is a mock to avoid business logic in example
function getCompany() {
return Math.random() ? new Company() : null;
}
class Logger {
private logAndTh