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

Add Examples for Contextual Components with Generics #2066

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kdagnan
Copy link

@kdagnan kdagnan commented Oct 25, 2024

I added some examples of yielding a contextual component with generic types to the "Invokables" typescript guides.

As part of this, I broke the "Advanced Signature Techniques" section into two sections: "Union Types" and "Generic Types", and updated the existing example to focus specifically on the Union Types while the new Generic Types examples show using Generic Types in a single component or with contextual components.

This is my first contribution so please let me know if I am missing anything or something looks off.

Copy link

netlify bot commented Oct 25, 2024

Deploy Preview for ember-guides ready!

Name Link
🔨 Latest commit 1268486
🔍 Latest deploy log https://app.netlify.com/sites/ember-guides/deploys/671c07e44b8ac10008193203
😎 Deploy Preview https://deploy-preview-2066--ember-guides.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

import Component from '@glimmer/component';

interface OrderedList<T> {
interface OrderedList {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The paragraph before this code block talks about generic types, but this PR has now removed the generics in this section. Probably, that paragraph should be moved to the new section farther down. I do think the note about class backing is important, but it may be sufficiently covered in the added section.

The item is
{{item}}.
</List>
<List @items={{array 1 2 3}} @type='unordered' {{reverse}} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't type-check since we've passed an array of numbers when an array of strings is expected.

Suggested change
<List @items={{array 1 2 3}} @type='unordered' {{reverse}} />
<List @items={{array "kdagnan" "gitKrystan" "wagenet"}} @type='unordered' {{reverse}} />


When consuming this component, Glint can infer the type of the yielded value to be the same as the type of `@items`:

```gts {data-filename="app/components/list-consumer.gts"}
Copy link
Contributor

@gitKrystan gitKrystan Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's switch these examples to ts + hbs for now. It's a bit confusing to switch between them in these docs. We should migrate all of these docs to gts at once in a separate PR.

@gitKrystan
Copy link
Contributor

Thanks for the contribution! ❤️ Just had a few small comments.

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.

3 participants