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

[typescript] 一个类型检查问题 #111

Open
yubaoquan opened this issue May 8, 2024 · 0 comments
Open

[typescript] 一个类型检查问题 #111

yubaoquan opened this issue May 8, 2024 · 0 comments

Comments

@yubaoquan
Copy link
Owner

const performTagsIntersection2 = (tags: string[], sql) => {
  console.info(tags.length)
  return sql
};

if (query.tags?.length) {
  sql = sql.where((builder) => performTagsIntersection(query.tags, builder)); // 为什么这里会提示 Argument of type 'string[] | undefined' is not assignable to parameter of type 'string[]'.}
}

因为 typescript 认为在执行 where 中的回调时, 可能 query.tags 已经发生了变化, 包括变成了 undefined

比如如下情形:

sql.where = (cb) => {
  query.tags = undefined
  const builder = xxx
  cb(builder)
}
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