ionic-team / ionic-team/ionic-framework

feat: improve Typescript support for `exactOptionalPropertyTypes`

未关闭
#30,005 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
type: feature request
主要语言
TypeScript
星标
52.7k
派生
13.3k
平均合并
1 天 15 小时
30 天内合并 PR
51

描述

### Prerequisites

- [X] I have read the [Contributing Guidelines](https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#creating-an-issue).
- [X] I agree to follow the [Code of Conduct](https://ionicframework.com/code-of-conduct).
- [X] I have searched for [existing issues](https://github.com/ionic-team/ionic-framework/issues) that already include this feature request, without success.

### Describe the Feature Request

[`exactOptionalPropertyTypes`](https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes) makes TypeScript truly enforce the definition provided matches the actual javascript value.

It's a recently added feature (v4.4) that is increasing in use.

However, many of Ionic's types are incompatible with `exactOptionalPropertyTypes`. This is because they define types as this:

```ts
"shape"?: 'round';
```

and not this:

```ts
"shape"?: 'round' | undefined;
```

It is worth noting that core React types follow the latter convention. Example:

image

### Describe the Use Case

See above.

### Describe Preferred Solution

Unless there is a specific reason, all Ionic attributes with `?` also list `undefined` as an explicit accepted value.

### Describe Alternatives

Not using `exactOptionalPropertyTypes` will opt the user out of many benefits, but it is a workaround for now.

### Related Code

_No response_

### Additional Information

This could also be considered a bug for certain attributes, since certain types, like [`className` defined here](https://github.com/ionic-team/ionic-framework/blob/4bffe976d937e21c42649d010ce696b19962f6ef/packages/react/src/components/react-component-lib/interfaces.ts#L8) don't actually conform with the React `className` attribute:

image

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。