Skip to content

Expose @glint/template utility types - #285

Merged
dfreeman merged 4 commits into
mainfrom
native-componentlike
Apr 7, 2022
Merged

dfreeman merged 4 commits into
mainfrom
native-componentlike

Conversation

@dfreeman

@dfreeman dfreeman commented Apr 6, 2022

Copy link
Copy Markdown
Contributor

One of the pending items from #283 is providing projects using native imports and signatures with a way to describe the type of yielded components, as @glint/environment-ember-loose's ComponentLike currently does. This is a vital piece for describing the signature of components that do things like:

{{yield (hash
  Input=(component "our-special-input" thing=this.defaultThingValue}}
)}}

Now that signature formats have been more or less standardized across the board, we can expose standardized ComponentLike, HelperLike and ModifierLike types from @glint/template itself rather than homing them in an environment-specific location. Subclasses of Component, Helper and Modifier are respectively assignable to their corresponding *Like types, as are the return values from helper() and modifier().

Each of these types is compatible as the first argument of a new WithBoundArgs helper, which will return an equivalent type except for any named args mentioned in the second argument being made optional. Capturing the above template example in a signature:

interface TheSignature {
  Blocks: {
    default: [{
      Input: WithBoundArgs<typeof OurSpecialInput, 'thing'>
    }];
  };
}

The @glint/template package is a types-only package that provides the baseline type declarations that all Glint environments are based on, and as such is something that addons can declare a dependency on without having any (even theoretical) runtime impact on their consumers.

@dfreeman dfreeman added the enhancement New feature or request label Apr 6, 2022
Base automatically changed from native-imports to main April 7, 2022 14:20
@dfreeman
dfreeman merged commit 4a3158d into main Apr 7, 2022
@dfreeman
dfreeman deleted the native-componentlike branch April 7, 2022 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant