feat(schemas): separate public from internal schema#29041
Conversation
|
Tip: Review these changes grouped by change (recommended for most PRs), or grouped by feature (for large PRs). |
d706910 to
16892e6
Compare
Otherwise `ajv` rejects the value for not being a string.
- Avoid unnecessary `tsType`. - Avoid descriptions next to `$ref` (causes duplicate types). - Refine descriptions.
Compares build output between PR and base.
This reverts commit 4869566.
`compat.support[browser]` may be the string `"mirror"` for source-tree
data; wrapping it in an array and returning it broke the
`SimpleSupportStatement[]` return contract. Since this helper has no
upstream context to resolve mirror, fall through to the existing
`[{ version_added: false }]` fallback instead.
Removes a `@ts-expect-error FIXME`.
`browserData` could be the string `"mirror"`, which the previous code wrapped in `["mirror"]` and iterated, relying on `@ts-expect-error` to silence the resulting type errors. Hoist the mirror check above the array-wrap so the loop body can rely on `browserData` being a `SimpleSupportStatement` or array thereof; the in-loop `'mirror'` branch becomes dead code and is removed. Removes two `@ts-expect-error FIXME`s.
`bumpSupport` accepts `InternalSupportStatement`, which includes the literal `"mirror"`, but `mirrorSupport` always resolves mirror before calling it. Make this contract explicit with a guard at the top of the function. The guard narrows `sourceData` for the entire function body, letting us drop the `@ts-expect-error` on `copyStatement(sourceData)` and remove five `typeof sourceData === 'object' &&` checks that were only there to narrow out the `"mirror"` case. Removes a `@ts-expect-error FIXME`.
The destructure reads `version_last`, which exists on the public `SimpleSupportStatement` (post-build) but not on `InternalSimpleSupportStatement`. Since `addVersionLast()` runs earlier in the same function, the public type accurately describes the runtime shape — switch the cast accordingly. Removes a `@ts-expect-error FIXME`.
Declaring `applyTransforms` as `asserts data is Omit<CompatData,
'__meta'>` lets TypeScript narrow `bcd` at the call site in
`createDataBundle`, so the spread `{...bcd, __meta: ...}` is
type-correct without suppression.
Removes a `@ts-expect-error`.
`source_file` belongs to the public `CompatStatement` shape, not the internal one, but is added at load time. Replace the `@ts-expect-error` with a localized JSDoc cast at the assignment site, which documents intent rather than just suppressing the error. Removes a `@ts-expect-error`.
LeoMcA
left a comment
There was a problem hiding this comment.
Nice! Looks ready to go from my side.
Tested breaking the types in multiple places (scripts/generate-types.js, types/index.d.ts and schemas/public.schema.json) and TS caught them all when running gentypes - very nice!
|
FYI @ddbeck Removing the example values from the type descriptions may have been technically correct, but it means the Typescript type declarations now longer have these. I fear this might be a regression in terms of developer experience, so I would suggest to revert this. How strongly do you feel about this? |
|
@caugner yes, that's fine. You can add examples back to the descriptions if that has a real benefit to developers. 👍 |
Each `compile` call prepends `bannerComment`, so concatenating multiple schema outputs duplicated the banner in `internal.d.ts`.
Done via 21ec227: Realized we can inject the examples into the descriptions at build time, so there's no risk of the descriptions/examples getting out of sync. 👍 Also noticed a duplicate banner, remoed via 5b92e5f. @LeoMcA Can you please take another look at these latest code changes? 🙏 |
Summary
Adds a public schema for
data.json, separate from the internal browser/compat file schemas.Also refines the schema descriptions based on Daniel's feedback.
Test results and supporting details
There are two changes that are strictly speaking breaking:
CompatStatement.source_fileproperty is now required.BrowserStatement.upstreamproperty is narrowed down toUpstreamBrowserName, a subset ofBrowserName.Before
After
diff
Related issues
Fixes #29059.