-
Notifications
You must be signed in to change notification settings - Fork 70
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 nested types output from createStrictAPI() being unintentionally marked as required #1604
Conversation
🦋 Changeset detectedLatest commit: a99f3f3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -5,6 +5,58 @@ import type { XCSSProp } from './__fixtures__/strict-api-recursive'; | |||
import { css, cssMap } from './__fixtures__/strict-api-recursive'; | |||
|
|||
describe('createStrictAPI()', () => { | |||
it('should mark all styles as optional in css()', () => { | |||
const styles = css({ | |||
'&:hover': {}, |
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.
This was a type violation previously.
: TObject[P] | ||
type EnforceSchema<TSchema> = { | ||
[P in keyof TSchema]?: P extends keyof CompiledSchema | ||
? TSchema[P] extends Record<string, any> |
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.
Fix: unknown
-> any
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.
Interesting, do you know why this works? I've seen similar things, just never seen like a TS issue or explanation.
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 it's an edge case with complex nested types (interface + omits + ?). At a glace unknown should be fine but in this case it's obviously not.
I'm not sure!
@@ -98,15 +98,15 @@ export const visitCssMapPath = ( | |||
const { sheets, classNames } = transformCssItems(css, meta); | |||
totalSheets.push(...sheets); | |||
|
|||
if (classNames.length !== 1) { | |||
if (classNames.length > 1) { |
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.
This allows us to make empty styles now (at least for testing).
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.
Seems straightforward from my understanding, and I know there's tests for '&:hover': { … }
having valid css in them, so LGTM.
: TObject[P] | ||
type EnforceSchema<TSchema> = { | ||
[P in keyof TSchema]?: P extends keyof CompiledSchema | ||
? TSchema[P] extends Record<string, any> |
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.
Interesting, do you know why this works? I've seen similar things, just never seen like a TS issue or explanation.
throw buildCodeFrameError( | ||
createErrorMessage(ErrorMessages.STATIC_VARIANT_OBJECT), | ||
property, | ||
meta.parentPath | ||
); | ||
} | ||
|
||
return t.objectProperty(property.key, classNames[0]); | ||
return t.objectProperty(property.key, classNames[0] || t.stringLiteral('')); |
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.
Got it, so having '&:hover'
empty threw this?
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.
Yeah exactly.
This pull request updates types and adds some tests for this specific use case.