fix: resolve TypeScript built-in type name collisions in CRD imports - #3801
Open
mateo-moon wants to merge 3 commits into
Open
fix: resolve TypeScript built-in type name collisions in CRD imports#3801mateo-moon wants to merge 3 commits into
mateo-moon wants to merge 3 commits into
Conversation
cdk8s-automation
enabled auto-merge
February 3, 2026 11:48
auto-merge was automatically disabled
February 3, 2026 11:48
Head branch was pushed to by a user without write access
mateo-moon
force-pushed
the
fix/builtin-type-name-collision
branch
2 times, most recently
from
February 3, 2026 11:52
c5b25e3 to
3cdaf99
Compare
When a CRD's kind name matches a TypeScript built-in utility type (e.g., "Record", "Map", "Set"), the generated code creates a class that shadows the built-in type. This causes TypeScript compilation errors when the generated toJson functions use types like `Record<string, any>`. This fix adds a post-processing step that: 1. Detects when a CRD kind matches a TypeScript built-in type 2. Adds a type alias (e.g., `JsonRecord<K, T>`) to preserve the built-in 3. Replaces usages of the built-in type with the alias Example: Cloudflare's DNS `Record` CRD would generate a `Record` class, and `Record<string, any>` usages are replaced with `JsonRecord<string, any>`. Signed-off-by: OP <op@cicd.ninja>
mateo-moon
force-pushed
the
fix/builtin-type-name-collision
branch
from
July 19, 2026 14:02
3cdaf99 to
caa1b79
Compare
Author
|
Rebased onto the current 2.x head. While running this patch in production we found three follow-up issues, and the fixes are now included here: the type alias is emitted only once for multi-version CRDs, runtime calls such as Object.entries/keys/values are redirected to a preserved _Object alias, and those runtime replacements are applied to every CRD generated into the same file. The full local test suite passes. This still addresses #3800, which remains open. @iliapolo could you approve the workflow run and review? |
When a CRD kind is 'Object', the generated class shadows globalThis.Object, breaking Object.entries(), Object.keys(), Object.assign() etc. in toJson functions. Now we emit 'const _Object = globalThis.Object;' and replace all runtime static method calls with the alias. Signed-off-by: OP <op@cicd.ninja>
When a CRD kind like 'Object' shadows a global constructor, the class definition affects ALL code in the generated file, not just code for that specific CRD. Previously, fixBuiltinTypeConflicts only replaced runtime calls (Object.entries, etc.) for the CRD whose kind matched the builtin. Now it collects all conflicting kinds at the file level and applies replacements to all CRDs in the same API group module. This fixes ProviderConfig's toJson functions in kubernetes.crossplane.io.ts where Object.entries was not being replaced even though class Object is defined earlier in the file. Signed-off-by: OP <op@cicd.ninja>
mateo-moon
force-pushed
the
fix/builtin-type-name-collision
branch
from
July 19, 2026 14:16
caa1b79 to
41a2254
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3800
When a CRD's kind name matches a TypeScript built-in utility type (e.g.,
Record,Map,Set), the generated code creates a class that shadows the built-in type. This causes TypeScript compilation errors when the generatedtoJson_*functions use types likeRecord<string, any>.Changes
Added a post-processing step in
src/import/crd.tsthat:type JsonRecord<K extends keyof any, T> = { [P in K]: T };) at the beginning of the generated fileRecord<string, any>→JsonRecord<string, any>)Example
For Cloudflare's DNS
RecordCRD, the generated code now includes:Test Plan
fixBuiltinTypeConflictsfunctionBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.