-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fixed an issue with typegen types not being able to provide events that had a union of strings as their type
#3230
Conversation
…at had a union of strings as their `type`
🦋 Changeset detectedLatest commit: 485a373 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
CodeSee Review Map:Review in an interactive map View more CodeSee Maps Legend |
packages/core/package.json
Outdated
"typesVersions": { | ||
"<4.1": { | ||
"lib/types.4.1.d.ts": [ | ||
"types.pre-4.1.d.ts" | ||
] | ||
} | ||
}, |
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 still need to verify in some external project that this will be resolved correctly
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 485a373:
|
packages/core/package.json
Outdated
@@ -15,7 +22,8 @@ | |||
"lib/**/*.js", | |||
"lib/**/*.d.ts", | |||
"es/**/*.js", | |||
"es/**/*.d.ts" | |||
"es/**/*.d.ts", | |||
"*.d.ts" |
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.
Is this one needed?
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.
The plan was to keep types targeting lowe versions of TS in this file and that would have to be published. However, it seems that it's not possible to redirect internal file requests (see here) so this strategy won't work.
To make it happen we would have to bundle all of our types, replace in it what we want, and point to that from typesVersions
. It's way more work than what I've wanted to pull off here so I'm going to just revert this part of the change (optimization) and keep it in a TODO comment for v5.
export type IndexByType<T extends { type: string }> = { | ||
[K in T['type']]: Extract<T, { type: K }>; | ||
[K in T['type']]: T extends any ? (K extends T['type'] ? T : never) : never; |
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 wonder why T extends any
makes this work 🧐
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.
https://github.com/statelyai/eng-blog/pull/81/files :P
This is just a way to make this conditional type distributive. Conditional types are distributive when they contain a "naked" type param:
type IsStringDistributive<T> = T extends string ? 1 : 0
// this will run the conditional type over each member of this union type
type Distributes = IsStringDistributive<string | number>
// ^? 1 | 0
type IsStringNonDistributive<T> = [T] extends [string] ? 1 : 0
// this will run the conditional type on the union type "as is"
type DoesntDistribute = IsStringNonDistributive<string | number>
// ^? 0
TS playground
TS playground with Omit variants
So this particular type here just checks if the current K
extends any of the T['type']
and it will match even if T['type']
is a union. Whereas the previous version would fail because
'FOO' | 'BAR' extends 'FOO' ? 1 : 0 // 0
…at had a union of strings as their `type` (statelyai#3230) * Fixed an issue with typegen types not being able to provide events that had a union of strings as their `type` * Remove `typesVersions` attempt from the core
fixes #3102
why and how? https://github.com/statelyai/eng-blog/pull/81/files