Skip to content

Conversation

@afc163
Copy link
Member

@afc163 afc163 commented Sep 18, 2025

close #1360

Summary by CodeRabbit

  • 重构
    • 优化内部类型定义的表达方式,提升可读性与一致性,对功能与运行时行为无影响。
  • 其他
    • 本次更新无用户可见变更,无需额外操作或升级指引。

@vercel
Copy link

vercel bot commented Sep 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
table Ready Ready Preview Comment Sep 18, 2025 3:53am

@coderabbitai
Copy link

coderabbitai bot commented Sep 18, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

在 src/interface.ts 中,将类型别名 SpecialString 的交叉类型由 string & unknown 调整为 string & NonNullable。该变更仅影响类型层面,无运行时改动或逻辑流程变更。

Changes

Cohort / File(s) Change summary
类型别名调整
src/interface.ts
将 `export type SpecialString = T

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

小兔挥笔轻一改,
字里行间风不摆。
unknown 化作 NonNullable,
类型如旧影还在。
代码无声草儿拍,
PR 合上月色白。

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning 根据提交摘要,本次将 SpecialString 从 T (string & unknown) 改为 T
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed PR 标题 "type: update SpecialString type to use NonNullable" 简洁明确,直接反映出本次变更的核心(更新 SpecialString 类型以使用 NonNullable),没有冗余词或模糊描述,能让审阅者快速识别主要改动并与变更内容直接相关。
Out of Scope Changes Check ✅ Passed 从提供的变更摘要来看,PR 仅修改了 src/interface.ts 中的 SpecialString 类型别名,未见其他文件改动或与关联 issue 目标无关的逻辑更改,因此没有发现范围外(out-of-scope)的代码修改。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch type/fix-dataIndex-infer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @afc163, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the SpecialString type definition by incorporating NonNullable<unknown> instead of unknown. This modification aims to enhance type safety and correctness, specifically addressing an identified issue related to how string intersection types handle potential null or undefined values. The change is part of an ongoing effort to improve the robustness of the codebase.

Highlights

  • Type Definition Update: The SpecialString type definition has been updated in src/interface.ts.
  • NonNullable Usage: The unknown type within the SpecialString definition was replaced with NonNullable<unknown> to refine type handling.
  • Issue Resolution: This change addresses and closes issue #1360, likely resolving a type-related bug or inconsistency.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Updates the SpecialString type definition to use NonNullable<unknown> instead of unknown for better type safety, addressing issue #1360.

  • Replace unknown with NonNullable<unknown> in the SpecialString type intersection

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


// SpecialString will be removed in antd@6
export type SpecialString<T> = T | (string & unknown);
export type SpecialString<T> = T | (string & NonNullable<unknown>);
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using NonNullable<unknown> is equivalent to unknown since unknown is already non-nullable. This change has no practical effect. Consider using NonNullable<{}> or {} instead if the intent is to exclude null/undefined from the intersection.

Suggested change
export type SpecialString<T> = T | (string & NonNullable<unknown>);
export type SpecialString<T> = T | (string & {});

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Don't use {} as a type. {} actually means "any non-nullish value".

  • If you want a type meaning "any object", you probably want object instead.
  • If you want a type meaning "any value", you probably want unknown instead.
  • If you want a type meaning "empty object", you probably want Record<string, never> instead.
  • If you really want a type meaning "any non-nullish value", you probably want NonNullable<unknown> instead.eslint@typescript-eslint/ban-types

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the SpecialString type to use NonNullable<unknown> instead of unknown. This is a good change that correctly implements the string & {} pattern in TypeScript to improve autocompletion for string literals while still allowing any string. I've added one comment regarding a potential pre-existing issue with the SpecialString< T> type definition itself, which seems to incorrectly allow a record object to be used as a dataIndex. While the change in this PR is correct, it's a good opportunity to highlight this related issue for future improvement.


// SpecialString will be removed in antd@6
export type SpecialString<T> = T | (string & unknown);
export type SpecialString<T> = T | (string & NonNullable<unknown>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This change correctly applies the string & {} pattern to improve autocompletion. However, the SpecialString< T> type itself appears to have a flaw.

By including T in its definition (T | ...), and since T becomes the RecordType when used in DataIndex, this type incorrectly allows a whole record object to be passed as a dataIndex. This is likely a bug.

A more correct approach would be to remove T from the union. For example:

export type SpecialString = string & NonNullable<unknown>;

This would then require updating its usage in DataIndex on lines 88 and 90 (e.g., ... | SpecialString | ...).

Given this change is out of scope for the current PR, consider creating a follow-up issue or PR to address this typing issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gemini-code-assist Don't use {} as a type. {} actually means "any non-nullish value".

If you want a type meaning "any object", you probably want object instead.
If you want a type meaning "any value", you probably want unknown instead.
If you want a type meaning "empty object", you probably want Record<string, never> instead.
If you really want a type meaning "any non-nullish value", you probably want NonNullable<unknown> instead.eslint[@typescript-eslint/ban-types](https://typescript-eslint.io/rules/ban-types)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification, @afc163. You are absolutely correct that {} should generally be avoided as a type, and NonNullable<unknown> is indeed the appropriate way to represent 'any non-nullish value' in TypeScript. My apologies for using {} as a shorthand in my previous comment when referring to the pattern.

My primary concern, however, remains with the inclusion of T in the SpecialString<T> definition (T | (string & NonNullable<unknown>)). As T becomes RecordType when SpecialString is used within DataIndex, this type currently allows an entire record object to be passed as a dataIndex, which seems unintended and could lead to runtime issues.

The suggestion to define SpecialString as export type SpecialString = string & NonNullable<unknown>; (without the generic T) and then update its usage in DataIndex was aimed at addressing this specific issue, ensuring that dataIndex only accepts string-like values or DeepNamePath<T>, but not the full RecordType itself.

I believe addressing the T in SpecialString<T> is important for type correctness, even if it's considered out of scope for this particular PR.

@codecov
Copy link

codecov bot commented Sep 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.10%. Comparing base (e082bea) to head (38d86a9).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1361   +/-   ##
=======================================
  Coverage   96.10%   96.10%           
=======================================
  Files          57       57           
  Lines        3441     3441           
  Branches      630      630           
=======================================
  Hits         3307     3307           
  Misses        129      129           
  Partials        5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/interface.ts (1)

84-84: 该改动是 no‑op,无法修复 #1360 指出的“DataIndex 精确度丢失”

NonNullable<unknown>unknown 等价,string & NonNullable<unknown> 仍会化简为 string,不会恢复基于 string & {} 的补全/精确度行为。建议直接回退为 string & {}(或等价的 string & NonNullable<{}>)。

-export type SpecialString<T> = T | (string & NonNullable<unknown>);
+export type SpecialString<T> = T | (string & {});
TypeScript 中 `NonNullable<unknown>` 是否等于 `unknown`?`string & NonNullable<unknown>` 会不会化简为 `string`?
🧹 Nitpick comments (1)
src/interface.ts (1)

86-90: SpecialString 将整个 RecordType 也纳入 DataIndex,可导致把对象误传给 dataIndex

由于 SpecialString<T> 包含 TDataIndex<T> 现有定义允许把整条记录对象作为 dataIndex 传入(类型层面不报错)。这与期望的「键路径/键名/索引」语义不符。建议后续移除 T,仅保留“带品牌”的字符串类型,并相应更新 DataIndex。为避免在当前 PR 扩大变更面,建议另起 PR 处理。

可选后续修正示例(单独 PR 执行):

- export type SpecialString<T> = T | (string & {});
+ export type SpecialString = string & {};

 export type DataIndex<T = any> =
   | DeepNamePath<T>
-  | SpecialString<T>
+  | SpecialString
   | number
-  | (SpecialString<T> | number)[];
+  | (SpecialString | number)[];
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e082bea and 38d86a9.

📒 Files selected for processing (1)
  • src/interface.ts (1 hunks)

@afc163 afc163 merged commit ef42be4 into master Sep 18, 2025
13 checks passed
@afc163 afc163 deleted the type/fix-dataIndex-infer branch September 18, 2025 07:46
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

Successfully merging this pull request may close these issues.

DataIndex 精确度丢失

2 participants