hannnnxiiii opened a new pull request, #21747:
URL: https://github.com/apache/echarts/pull/21747
<!-- Please fill in the following information to help us review your PR more
efficiently. -->
## Brief Information
This pull request is in the type of:
- [x] 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
- #21746
## Details
### Before: What was the problem?
Setting `xAxis`/`yAxis` `min`/`max` directly to `null`/`undefined` failed
TypeScript compilation (with `strictNullChecks` enabled):
```ts
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`:
```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.
- [x] 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
- [x] Please squash the commits into a single one when merging.
### Other information
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]