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

Support inheritance when parsing interfaces #395

Merged
merged 2 commits into from
Oct 5, 2023
Merged

Conversation

nmanu1
Copy link
Contributor

@nmanu1 nmanu1 commented Oct 4, 2023

This PR adds support for inherited properties when parsing interfaces such as component prop interfaces or site settings. Something like this is now supported:

import { CtaData } from "@yext/search-ui-react";

interface BaseProps {
  title: string;
}

interface ComponentProps extends BaseProps, CtaData {
  description: string;
}

If we're not able to resolve the type that's being extended to an object type, we throw an error. This would include extending a non-object type like HexColor (which is invalid TS), extending a built-in type like Record, etc. We also aren't adding any additional support for type unions or intersections, beyond our current support for string unions, since TS does more complicated merging when properties are shared in those cases. For interfaces that inherit properties, if a property is shared between the inherited type and the new type, the new property's type is required by TS to be a subset of the inherited property's type, and the new property's type is used in the final, generated type. In other words, only type narrowing is allowed.

J=SLAP-2938
TEST=auto, manual

In the test-site, see that prop editors for inherited props show up as expected in the UI.

@tmeyer2115 tmeyer2115 self-requested a review October 5, 2023 13:59
@nmanu1 nmanu1 merged commit 4c4965d into main Oct 5, 2023
15 checks passed
@nmanu1 nmanu1 deleted the dev/interface-inheritance branch October 5, 2023 14:19
@tmeyer2115 tmeyer2115 mentioned this pull request Oct 11, 2023
tmeyer2115 added a commit that referenced this pull request Oct 11, 2023
## Features
- When specifying a Component's Prop Interface, you can now use the
`extends` keyword. (#395)

## Changes
- Cached, pre-bundled dependencies are now ignored when starting Studio.
Studio's Vite instance will pre-bundle all dependencies each time Studio
is started. (#405)
- Props with a Tooltip now have an Info Icon (#403)

## Fixes
- Incorrect imports for commonly-named Components have been fixed.
(#398)
alextaing pushed a commit that referenced this pull request Oct 11, 2023
## Features
- When specifying a Component's Prop Interface, you can now use the
`extends` keyword. (#395)

## Changes
- Cached, pre-bundled dependencies are now ignored when starting Studio.
Studio's Vite instance will pre-bundle all dependencies each time Studio
is started. (#405)
- Props with a Tooltip now have an Info Icon (#403)

## Fixes
- Incorrect imports for commonly-named Components have been fixed.
(#398)
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