fix: resolve TypeScript built-in type name collisions in CRD imports#3801
Open
mateo-moon wants to merge 1 commit intocdk8s-team:2.xfrom
Open
fix: resolve TypeScript built-in type name collisions in CRD imports#3801mateo-moon wants to merge 1 commit intocdk8s-team:2.xfrom
mateo-moon wants to merge 1 commit intocdk8s-team:2.xfrom
Conversation
auto-merge was automatically disabled
February 3, 2026 11:48
Head branch was pushed to by a user without write access
f585e0b to
c5b25e3
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>
c5b25e3 to
3cdaf99
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.