Skip to content
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

TypeScript readonly error #3293

Closed
ChristofferOakDigital opened this issue May 15, 2024 · 0 comments · Fixed by #3308
Closed

TypeScript readonly error #3293

ChristofferOakDigital opened this issue May 15, 2024 · 0 comments · Fixed by #3308

Comments

@ChristofferOakDigital
Copy link

Describe the bug
We are trying to create type interfaces for Props to our React components, which requires as const, however the inputs cannot be readonly

To Reproduce
Steps to reproduce the behavior:

export const builderColorTheme = {
    name: 'colorTheme',
    type: 'text',
    enum: ['light', 'dark', 'faded'],
    defaultValue: 'light',
} as const;

export const registerPricingTable = {
    name: 'PricingTable',
    noWrap: true,
    inputs: [
        builderColorTheme,
    ],
} as const satisfies Component;

Expected behavior
Being able to assign readonly

Additional context
We would like this to be readonly

Alexnortung added a commit to Oak-Digital/builder that referenced this issue May 30, 2024
samijaber added a commit that referenced this issue May 30, 2024
## Description

It should be possible to assign readonly types to `Component` and other
`@builder.io/sdk` types, since no mutations are(/should) happening.

This is needed to make type inference working in the
[`@oak-digital/builder-helpers`](https://github.com/Oak-Digital/builder-helpers)
package.

See the following example:

```ts
import Counter from './counter';

const registerCounter = {
    name: 'Counter',
    inputs: [
        {
            name: 'text',
            type: 'string',
        },
    ];
} as const;

Builder.registerComponent(Counter, registerCounter);
```

This example would result in a type error while registering the
component to builder. This is not really desired, so this PR makes it
possible to ALSO assign readonly types.

This PR fixes #3293

---------

Co-authored-by: Sami Jaber <me@sami.website>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant