智能客服
你问我答,随时在线为你解决问题

























不允许在布尔表达式中使用非布尔类型。
- // code-linter.json5
- {
- "rules": {
- "@typescript-eslint/strict-boolean-expressions": "error"
- }
- }
- // nullable values should be checked explicitly against null or undefined
- function getNum(): number | undefined {
- return undefined;
- }
-
- const num: number | undefined = getNum();
- if (num !== undefined) {
- console.log('num is defined');
- }
-
- function getStr(): string | null {
- return 'null';
- }
-
- const str: string | null = getStr();
- if (str !== null) {
- console.log('str is not empty');
- }
- // nullable values should be checked explicitly against null or undefined
- function getNum(): number | undefined {
- return undefined;
- }
-
- const num: number | undefined = getNum();
- if (num) {
- console.log('num is defined');
- }
-
- function getStr(): string | null {
- return 'null';
- }
-
- const str: string | null = getStr();
- if (str) {
- console.log('str is not empty');
- }
智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功