Skip to content

关于第4章,1.8节”没有声明类型的变量,被赋值为undefined或null,它们的类型会被推断为any” 的问题 #64

Closed
@StrongerLph

Description

@StrongerLph

这一小段有点问题,https://wangdoc.com/typescript/types#undefined-%E7%B1%BB%E5%9E%8Bnull-%E7%B1%BB%E5%9E%8B。
开启了strictNullChecks,const b = undefined 应该被推断为undefined类型,const d = null 应该推断为 null类型。

具体原因不懂,个人认为是因为const定义的变量不可修改,所以定义时就可以推断出类型。

1692602525185

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions