Skip to content

fix: prevent mixing responsive viewport keys with T's keys in Responsive<T>#600

Open
te6-in wants to merge 1 commit intoreshaped-ui:canaryfrom
te6-in:canary
Open

fix: prevent mixing responsive viewport keys with T's keys in Responsive<T>#600
te6-in wants to merge 1 commit intoreshaped-ui:canaryfrom
te6-in:canary

Conversation

@te6-in
Copy link
Copy Markdown

@te6-in te6-in commented Mar 12, 2026

Hi, first of all, congrats on and thanks for opensourcing reshaped, really enjoying digging the codebase.

I noticed a small type safety gap in Responsive<T> and wanted to contribute a fix.

Summary

Regarding ResponsiveOnly<T>, currently when T is an object like ButtonProps, it allows mixing T's keys with viewport keys without a type error.

const buttonProps = useResponsiveClientValue<ButtonProps>({
  s: { variant: "solid" },
  xl: { variant: "outline" },
  onClick: () => {},  // no error
});

This PR adds an intersection to ResponsiveOnly<T> so that T's own keys would be mapped to never.

Related Issue

not found so far

Notes for Reviewers

While this makes codes like above make type error, IDE still suggests T's keys in autocompletions. I guess this is a TypeScript limitation.

@te6-in te6-in changed the title fix: prevent mixing responsive viewport keys with value keys in Responsive<T> fix: prevent mixing responsive viewport keys with value T's keys in Responsive<T> Mar 12, 2026
@te6-in te6-in changed the title fix: prevent mixing responsive viewport keys with value T's keys in Responsive<T> fix: prevent mixing responsive viewport keys with T's keys in Responsive<T> Mar 12, 2026
@te6-in
Copy link
Copy Markdown
Author

te6-in commented Mar 16, 2026

@blvdmitry Hey sure, Playground

  • added type Responsive<T> = T | ResponsiveOnly<T> to reproduce the issue
  • used variant instead of onClick since onClick doesn't exist in ButtonProps in the playground example

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 this pull request may close these issues.

2 participants