Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] tsconfig 是否应该开启 strict 或 strictNullChecks #423

Open
xliez opened this issue Feb 23, 2023 · 1 comment
Open

[RFC] tsconfig 是否应该开启 strict 或 strictNullChecks #423

xliez opened this issue Feb 23, 2023 · 1 comment

Comments

@xliez
Copy link

xliez commented Feb 23, 2023

WHY:不开启strictNullChecks的话会忽略所有的 null 和 undefined

举个例子:

useMergedState 中接受了泛型T作为内部的 innerValue 类型,但根据 L60 开始的代码

  // Sync value back to `undefined` when it from control to un-control
  useLayoutUpdateEffect(() => {
    if (!hasValue(value)) {
      setInnerValue(value);
    }
  }, [value]);

实际上 innerValue 的类型是T | undefined,因为没有开启 strictNullChecks 导致没有警告

该函数使用中,需要显性去指定泛型为 T | undefined 才能获取到实际正确的类型,如:

const [v] = useMergedState<string[]>(...) => const [v] = useMergedState<string[] | undefined>(...)

前者的写法,v的类型会忽略 undefined类型,导致后续编码产生错误

以上为我在debug该issue时发现: ant-design/pro-components#6652

个人见解,欢迎讨论😁

@xliez
Copy link
Author

xliez commented Feb 24, 2023

@MadCcc @zombieJ

大佬们cc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant