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

Fix optional property types #6872

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/@internationalized/date/src/DateFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

let formatterCache = new Map<string, Intl.DateTimeFormat>();

interface ResolvedDateTimeFormatOptions extends Intl.ResolvedDateTimeFormatOptions {
hourCycle?: Intl.DateTimeFormatOptions['hourCycle']
}

interface DateRangeFormatPart extends Intl.DateTimeFormatPart {
source: 'startRange' | 'endRange' | 'shared'
}
Expand Down Expand Up @@ -79,8 +75,8 @@ export class DateFormatter implements Intl.DateTimeFormat {
}

/** Returns the resolved formatting options based on the values passed to the constructor. */
resolvedOptions(): ResolvedDateTimeFormatOptions {
let resolvedOptions = this.formatter.resolvedOptions() as ResolvedDateTimeFormatOptions;
resolvedOptions(): Intl.ResolvedDateTimeFormatOptions {
let resolvedOptions = this.formatter.resolvedOptions();
if (hasBuggyResolvedHourCycle()) {
if (!this.resolvedHourCycle) {
this.resolvedHourCycle = getResolvedHourCycle(resolvedOptions.locale, this.options);
Expand Down Expand Up @@ -156,10 +152,10 @@ function hasBuggyHour12Behavior() {
let _hasBuggyResolvedHourCycle: boolean | null = null;
function hasBuggyResolvedHourCycle() {
if (_hasBuggyResolvedHourCycle == null) {
_hasBuggyResolvedHourCycle = (new Intl.DateTimeFormat('fr', {
_hasBuggyResolvedHourCycle = new Intl.DateTimeFormat('fr', {
hour: 'numeric',
hour12: false
}).resolvedOptions() as ResolvedDateTimeFormatOptions).hourCycle === 'h12';
}).resolvedOptions().hourCycle === 'h12';
}

return _hasBuggyResolvedHourCycle;
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-types/shared/src/dom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
FormEventHandler,
HTMLAttributeAnchorTarget,
HTMLAttributeReferrerPolicy,
HTMLAttributes,
DOMAttributes as ReactDOMAttributes,
ReactEventHandler
} from 'react';
Expand Down Expand Up @@ -59,7 +60,7 @@ export interface DOMProps {
/**
* The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).
*/
id?: string
id?: string | undefined
Copy link
Member

Choose a reason for hiding this comment

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

this looks correct, but is really going to need to exist in so many more places
https://github.com/microsoft/TypeScript/blob/a86b5e2b01075db5046521958a3e0b905b4ca667/tests/lib/react18/react18.d.ts#L1863

Any way we can use the type from the original set instead of creating our own? maybe extends Pick<HTMLElement, 'id'>?

Copy link
Author

Choose a reason for hiding this comment

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

The focus of this PR is to just fix the public API. I don't see anything wrong with adding | undefined in more places, but that's #1890.

Updated to use extends πŸ˜‰

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I guess i'm worried about potential regressions, and I'm also not sure that this is really all there is to fix in the public API, seems like too small a change?

Copy link
Author

Choose a reason for hiding this comment

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

You're right, there's most likely more, I only submitted the changes necessary to unblock our particular cocktail of Spectrum πŸ˜› I'll create more PRs in the future as I run into other issues.

Hopefully #1890 will be addressed soon, but until then, one option could be to add a quick smoke test, that just lists every single package as a dependency and runs tsc with skipLibCheck: false, strict: true and exactOptionalPropertyTypes: true? This will allow you to make sure that the public API is clean, without switching the whole monorepo to exactOptionalPropertyTypes: true.

}

export interface FocusableDOMProps extends DOMProps {
Expand Down