-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
chore: upgrade typescript to 5.5.2 #33498
base: master
Are you sure you want to change the base?
Conversation
@@ -85,7 +91,9 @@ export function classNamesFunction<TStyleProps extends {}, TStyleSet extends ISt | |||
typeof styleFunctionOrObject === 'function' && | |||
(styleFunctionOrObject as StyleFunction<TStyleProps, TStyleSet>).__noStyleOverride__ | |||
) { | |||
return styleFunctionOrObject(styleProps) as IProcessedStyleSet<TStyleSet>; | |||
return (styleFunctionOrObject as IStyleFunction<TStyleProps, TStyleSet>)( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string' | ||
? asProp || state.components?.[slotName] || 'div' | ||
: state.components[slotName] | ||
) as React.ElementType<R[K]>; | ||
: state.components[slotName]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after upgrade throws TS2590: Expression produces a union type that is too complex to represent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's strange, there shouldn't be difference between asserting on definition vs this artificial alias you created. can you double check please ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a difference for how TS is processing it, it's too complex for TS to handle assertion context in the first case, as it's attempting to make a full type validation against of a both ternary branches 🤷🏻
Smth like this should also work:
const slot: React.ElementType<R[K]> =
state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'
? ((asProp || state.components?.[slotName] || 'div') as React.ElementType<R[K]>)
: (state.components[slotName] as React.ElementType<R[K]>);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are various false positives in this implementation starting with return type readonly [React.ElementType<R[K]> | null, R[K]]
, but what is being done inside is casting the slot to React.ElementType<R[K]>
instead of explicit union with null.
anyways...
the slot variable instantiation is so overly complex that it is impossible to capture a proper type from all these inline short-circuit checks
at this stage we should do following.
const slot = (state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'
? asProp || state.components[slotName] || 'div'
: state.components[slotName]) as unknown as React.ElementType<R[K]>;
- no extra JS runtime
- less complex for TSC to figure out things
- better express the intent as the result expression is truly unknown :)
29cadea
to
ea576b0
Compare
ea576b0
to
3ee9cbd
Compare
Pull request demo site: URL |
3ee9cbd
to
83e4110
Compare
📊 Bundle size reportUnchanged fixtures
|
0e865c5
to
0a3b8eb
Compare
9f52366
to
415da9a
Compare
415da9a
to
eccd0d4
Compare
@@ -15,7 +15,9 @@ export function concatStyleSetsWithProps<TStyleProps, TStyleSet extends IStyleSe | |||
const result: Array<DeepPartial<TStyleSet>> = []; | |||
for (const styles of allStyles) { | |||
if (styles) { | |||
result.push(typeof styles === 'function' ? styles(styleProps) : styles); | |||
result.push( | |||
typeof styles === 'function' ? (styles as IStyleFunction<TStyleProps, TStyleSet>)(styleProps) : styles, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checked this a bit more.
because the IStyleFunctionOrObject
type is very complex ( including recursion ), the typeof function
check is not enough to narrow down the right value from the union.
Cleaner solution is to introduce custom type guard to help TS navigate in these non trivial waters ( might lead also to faster tsc )
export function isStyleFunction<TStylesProps, TStyleSet extends IStyleSetBase>(
val: IStyleFunctionOrObject<TStylesProps, TStyleSet>,
): val is IStyleFunction<TStylesProps, TStyleSet> {
return typeof val === 'function';
}
⬇️
result.push(isStyleFunction(styles) ? styles(styleProps) : styles);
no errors ✅.
similar approach can be used also in other related changes you made as part of this PR.
chore(utilities): update api.md chore(react-utilities): update api.md chore(style-utilities): update api.md
4f245a3
to
701f5a5
Compare
🕵 FluentUIV0 No visual regressions between this PR and main |
@import
JSDoc tags.Release notes
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-4.html
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html
Related to configDir template var: the initial assumption, that it will help to get rid of explicit typeRoots for
tsconfig.cy.json
files appeared to be wrong. It works for scenarios, where derived config (packages//tsconfig.json) has to have paths related to final directory, before it was needed to re-specify the config property for derived config.Previous Behavior
5.3.3
New Behavior
5.5.2
Related Issue(s)
(nx run-many -t build type-check --skip-nx-cache)