Skip to content

fix(type): allow null/undefined for axis min and max option - #21747

Merged
plainheart merged 1 commit into
apache:releasefrom
hannnnxiiii:fix-axis-min-max-nullable-type
Sep 4, 2026
Merged

fix(type): allow null/undefined for axis min and max option#21747
plainheart merged 1 commit into
apache:releasefrom
hannnnxiiii:fix-axis-min-max-nullable-type

Conversation

@hannnnxiiii

Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Allow null/undefined to be passed as direct values of the axis min/max option in the TypeScript type definitions, since they are already supported at runtime and documented.

Fixed issues

Details

Before: What was the problem?

Setting xAxis/yAxis min/max directly to null/undefined failed TypeScript compilation (with strictNullChecks enabled):

const option: echarts.EChartsOption = {
    yAxis: { min: null, max: null }
};

Type '{ min: null; max: null; }' is not assignable to type 'YAXisOption | YAXisOption[] | undefined'.

#21313 added NullUndefined only to the function return type of min/max, but not to the direct value union. Since ScaleDataValue (number | string | Date) does not include null, passing it directly still failed the type check, although the JSDoc above the option documents null/undefined: auto decide min value and it works at runtime.

After: How does it behave after the fixing?

Added NullUndefined to the direct value union of the min/max option type in src/coord/axisCommonTypes.ts:

min?: ScaleDataValue | 'dataMin' | NullUndefined
    | ((extent: {min: number, max: number}) => ScaleDataValue | NullUndefined);

null/undefined now type-check both as direct values and as function return values, matching the documented behavior (https://echarts.apache.org/en/option.html#yAxis.max).

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

Added a type test case test/types/esm/axisMinMaxNullable.ts, which covers both the direct value form (min: null, max: undefined) and the function form (min: () => null, max: () => undefined), verified with npm run test:dts:fast under strict mode across TypeScript 3.5 – 5.9.

Merging options

  • Please squash the commits into a single one when merging.

Other information

@echarts-bot

echarts-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only.

@plainheart plainheart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi, the change looks good to me. Can you change the target branch to the release branch?

@plainheart plainheart added this to the 6.1.1 milestone Sep 4, 2026
@hannnnxiiii
hannnnxiiii changed the base branch from master to release September 4, 2026 02:34
@hannnnxiiii
hannnnxiiii force-pushed the fix-axis-min-max-nullable-type branch from 1aba2ce to 7d8ad6b Compare September 4, 2026 02:40
@pull-request-size pull-request-size Bot added size/XS and removed size/L labels Sep 4, 2026
@hannnnxiiii

Copy link
Copy Markdown
Author

Thanks! I've changed the target branch to release and rebased the changes onto it.

@plainheart
plainheart merged commit cd9de60 into apache:release Sep 4, 2026
2 checks passed
@echarts-bot

echarts-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

Congratulations! Your PR has been merged. Thanks for your contribution! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Axis min/max option does not accept null/undefined as direct value in TypeScript

2 participants