-
Notifications
You must be signed in to change notification settings - Fork 5.3k
feat(sdk): improve configurable_prop
types
#16698
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
base: master
Are you sure you want to change the base?
feat(sdk): improve configurable_prop
types
#16698
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
|
""" WalkthroughThe update enhances the SDK's type definitions for configurable component properties by introducing new property types, including array variants and specialized service types. It refines existing types, expands the union and conditional types to cover new cases, and improves type safety by updating generic defaults and adding explicit options and defaults for string properties. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Component
participant SDK
User->>Component: Define configurable properties (with new types)
Component->>SDK: Pass properties with type annotations
SDK-->>Component: Validate and infer types (including arrays, services)
Component-->>User: Expose strongly-typed configuration interface
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/sdk/src/shared/component.ts (1)
167-204
: Conditional chain inPropValue
is becoming brittle
PropValue
now contains 20+ nested ternaries.
While it compiles, the growing depth:
- hurts readability and maintenance,
- complicates debugging when a new type is appended in the wrong spot,
- risks hitting the TS recursion limit.
A more maintainable pattern is a lookup map plus an indexed access:
type PropValueMap = { alert: never; any: any; // eslint-disable-line @typescript-eslint/no-explicit-any app: { authProvisionId: string }; boolean: boolean; "boolean[]": boolean[]; integer: number; "integer[]": number[]; number: number; "number[]": number[]; object: object; string: string; "string[]": string[]; "$.discord.channel": string; "$.discord.channel[]": string[]; "$.interface.http": unknown; "$.interface.timer": unknown; "$.service.db": unknown; datastore: unknown; http_request: unknown; sql: unknown; }; export type PropValue<T extends keyof PropValueMap> = PropValueMap[T];This flattens complexity, makes compiler errors point directly at the mapping entry, and eases future additions (one line per new type).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (1)
packages/sdk/src/shared/component.ts
(5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Lint Code Base
packages/sdk/src/shared/component.ts
Outdated
export type ConfigurablePropNumber = BaseConfigurableProp & { | ||
type: "number"; | ||
min?: number; | ||
max?: number; | ||
} & Defaultable<number>; | ||
export type ConfigurablePropNumberArray = BaseConfigurableProp & { | ||
type: "number[]"; | ||
} & Defaultable<number>; | ||
export type ConfigurablePropIntegerArray = BaseConfigurableProp & { | ||
type: "integer[]"; | ||
} & Defaultable<number>; | ||
export type ConfigurablePropBooleanArray = BaseConfigurableProp & { | ||
type: "boolean[]"; | ||
} & Defaultable<boolean>; | ||
export type ConfigurablePropDiscordChannel = BaseConfigurableProp & { | ||
type: "$.discord.channel"; | ||
[key: string]: unknown; | ||
} & Defaultable<string>; | ||
export type ConfigurablePropDiscordChannelArray = BaseConfigurableProp & { | ||
type: "$.discord.channel[]"; | ||
[key: string]: unknown; | ||
} & Defaultable<string>; |
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.
🛠️ Refactor suggestion
Array prop defaults / options currently accept scalar values
The four definitions below inherit Defaultable<scalar>
and therefore expose the wrong surface in editors and generated JSON schemas:
ConfigurablePropNumberArray
ConfigurablePropIntegerArray
ConfigurablePropBooleanArray
ConfigurablePropDiscordChannelArray
Either:
- Create
type DefaultableArray<T> = { default?: T[]; options?: T[] }
and use that, or - Inline the correct fields as shown in the previous comment.
This minor refactor removes an entire class of silent runtime bugs while keeping the public API intact.
🤖 Prompt for AI Agents
In packages/sdk/src/shared/component.ts between lines 98 and 119, the array
types ConfigurablePropNumberArray, ConfigurablePropIntegerArray,
ConfigurablePropBooleanArray, and ConfigurablePropDiscordChannelArray
incorrectly use Defaultable with scalar types, causing defaults and options to
accept scalar values instead of arrays. To fix this, define a new type
DefaultableArray<T> with default and options as optional arrays of T, then
replace Defaultable<T> with DefaultableArray<T> in these array type definitions
to ensure defaults and options are arrays, preventing runtime bugs.
type Defaultable<T> = { default?: T; options?: T[] }; | ||
|
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.
Defaultable is too restrictive for “array-of-X” property kinds
Defaultable<T>
hard-codes options?: T[]
.
When you reuse it for array property kinds ("number[]"
, "integer[]"
, "boolean[]"
, etc.) you end up with:
default?: number; // should be number[]
options?: number[]; // should be number[]
Consequently default
and PropValue<"number[]">
become incompatible and the compiler will not prevent the error because the mismatch sits in different structural types (prop definition vs. configured value).
Consider introducing a dedicated helper for array props or inlining default
/ options
:
-export type ConfigurablePropNumberArray = BaseConfigurableProp & {
- type: "number[]";
-} & Defaultable<number>;
+export type ConfigurablePropNumberArray = BaseConfigurableProp & {
+ type: "number[]";
+ default?: number[];
+ options?: number[];
+};
Same adjustment is required for ConfigurablePropIntegerArray
, ConfigurablePropBooleanArray
, and ConfigurablePropDiscordChannelArray
.
Failing to do so will allow mis-typed defaults to slip into published schema and break user tooling at runtime.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
type Defaultable<T> = { default?: T; options?: T[] }; | |
export type ConfigurablePropNumberArray = BaseConfigurableProp & { | |
type: "number[]"; | |
default?: number[]; | |
options?: number[]; | |
}; |
🤖 Prompt for AI Agents
In packages/sdk/src/shared/component.ts around lines 57 to 58, the
Defaultable<T> type is too restrictive because it defines options as T[] and
default as T, which causes type mismatches for array property kinds like
"number[]". To fix this, create a separate helper type specifically for array
properties where both default and options are arrays of T (e.g., default?: T[];
options?: T[][] or appropriate array types), and update
ConfigurablePropIntegerArray, ConfigurablePropBooleanArray, and
ConfigurablePropDiscordChannelArray accordingly to use this new helper, ensuring
type compatibility and preventing mis-typed defaults.
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.
Actionable comments posted: 0
♻️ Duplicate comments (3)
packages/sdk/src/shared/component.ts (3)
57-57
: Type is correctly defined, but consider the implications for array propertiesThe
Defaultable<T>
type is defined correctly, but as noted in previous reviews, this type becomes problematic when applied to array properties.
98-103
:⚠️ Potential issueArray prop defaults still accept scalar values
The
ConfigurablePropIntegerArray
andConfigurablePropBooleanArray
types inheritDefaultable<number>
andDefaultable<boolean>
respectively, which means theirdefault
property accepts scalar values (number/boolean) instead of arrays (number[]/boolean[]).This should be fixed by either:
- Creating a specific type for array defaults:
+type DefaultableArray<T> = { default?: T[]; options?: T[] }; export type ConfigurablePropIntegerArray = BaseConfigurableProp & { type: "integer[]"; -} & Defaultable<number>; +} & DefaultableArray<number>;
- Or by explicitly specifying the correct field types:
export type ConfigurablePropIntegerArray = BaseConfigurableProp & { type: "integer[]"; -} & Defaultable<number>; + default?: number[]; + options?: number[]; };Apply the same solution to
ConfigurablePropBooleanArray
.
104-111
:⚠️ Potential issueDiscord channel array type has incorrect default type
Similar to the integer and boolean arrays, the
ConfigurablePropDiscordChannelArray
type inheritsDefaultable<string>
, which means it accepts a scalar string as a default value instead of a string array.export type ConfigurablePropDiscordChannelArray = BaseConfigurableProp & { type: "$.discord.channel[]"; [key: string]: unknown; -} & Defaultable<string>; + default?: string[]; + options?: string[]; };
🧹 Nitpick comments (2)
packages/sdk/src/shared/component.ts (2)
113-133
: Good addition of specialized service and interface typesThe new specialized property types for interfaces and services are well-structured and appropriately use
[key: string]: unknown
to allow for additional properties that might be specific to each type.Consider adding JSDoc comments to document what additional properties each specialized type might accept for better developer guidance.
157-189
: Comprehensive property value type mappingThe expanded
PropValue<T>
conditional type correctly maps all property types to their corresponding TypeScript types, which ensures type safety when accessing property values.The deeply nested ternary structure could become hard to maintain as more types are added. Consider an alternative approach using a type lookup table:
type PropValueMap = { "alert": never; "any": any; "app": { authProvisionId: string }; "boolean": boolean; "boolean[]": boolean[]; "integer": number; "integer[]": number[]; "object": object; "string": string; "string[]": string[]; "$.discord.channel": string; "$.discord.channel[]": string[]; "$.interface.http": unknown; "$.interface.timer": unknown; "$.service.db": unknown; "datastore": unknown; "http_request": unknown; "sql": unknown; }; export type PropValue<T extends ConfigurableProp["type"]> = T extends keyof PropValueMap ? PropValueMap[T] : never;This approach is more maintainable and scales better when adding new types.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (1)
packages/sdk/src/shared/component.ts
(5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: test
- GitHub Check: pnpm publish
- GitHub Check: Lint Code Base
🔇 Additional comments (8)
packages/sdk/src/shared/component.ts (8)
59-61
: Good addition for more flexible string option definitionsThe new string option types provide more flexibility by allowing either plain strings or objects with labels and values. This will improve developer experience by enabling descriptive labels for dropdown options.
75-77
: Boolean type now properly supports defaults and optionsAdding
Defaultable<boolean>
to theConfigurablePropBoolean
type is a good improvement that ensures boolean properties can have default values and predefined options.
86-91
: Good explicit type definitions for string propertiesInstead of using
Defaultable<string>
, explicitly definingdefault
andoptions
with the newStringPropOption[]
type provides better flexibility for string properties with labeled options.
92-97
: Correct array typing for string arraysThe
ConfigurablePropStringArray
type correctly usesstring[]
for the default value type, which matches the property type. This prevents potential type errors at runtime.
135-153
: Complete union type including all new property typesThe
ConfigurableProp
union is properly updated to include all the new property types, ensuring they're recognized throughout the codebase.
191-193
: Minor formatting improvementThe addition of a semicolon after the property signature is a minor formatting improvement for consistency.
196-196
: Improved type safety with better generic defaultsChanging the default generic parameter from
any
toConfigurableProps
improves type safety by ensuring a sensible default rather than allowing any type.
205-207
: Consistent improvement in generic defaultsSimilar to
V1Component
, this change improves type safety by usingConfigurableProps
as the default generic parameter.
WHY
Many possible types were missing and/or not correctly defined.
Summary by CodeRabbit