




















这是一个创建于 896 天前的主题,其中的信息可能已经有所发展或是发生改变。
第一种:开启strictNullChecks。
interface C {
foo: string;
}
interface B {
c: C | null;
}
interface A {
b: B | null;
}
declare const a: A;
console.log(a.b!.c!.foo)
第二种:关闭strictNullChecks。
interface C {
foo: string;
}
interface B {
c: C;
}
interface A {
b: B;
}
const a: A = {
b: null,
};
大家更倾向于哪一种呢?
我个人现在用的第一种,但总感觉很麻烦。类型声明时要加个 null 倒还好,主要是每处调用都要加个!.或?.。
1 Trim21 2024 年 1 月 1 日 via Android开启 strictNullChecks |
2 infyni 2024 年 1 月 1 日开启 strictNullChecks 。 有时候后端真的会返回 null |
3 CLMan 2024 年 1 月 1 日1. strictNullChecks 肯定得开启吧,开启后 TS 就是 null safe 的语言了 |
4 hansomeneil 2024 年 1 月 1 日老板认可质量,不压缩工期,那就开,否则就别开,短期没有明显好处的事是很敏感、很难推进的。。等什么时候用户的要求提高了再说吧,否则纯粹是给自己增加工作量。。 |
5 RedNax 2024 年 1 月 2 日 via iPhone不开干嘛还写 TS 。 |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。