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

[IgxForOfDirective] use generic types #12182

Closed
pmoleri opened this issue Oct 11, 2022 · 4 comments
Closed

[IgxForOfDirective] use generic types #12182

pmoleri opened this issue Oct 11, 2022 · 4 comments
Assignees
Labels
🧰 feature-request virtualization ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged.

Comments

@pmoleri
Copy link

pmoleri commented Oct 11, 2022

Is your feature request related to a problem? Please describe.

When using igxForOf my items are inferred as type any.

e.g. <div *igxFor="let item of [1,2,3]"></div>

image

Describe the solution you'd like

I'd like the directive to take advantage of generics to get proper types in my items.

Describe alternatives you've considered

None

@pmoleri
Copy link
Author

pmoleri commented Oct 26, 2022

The trick is adding a declaration like this (copied from ngFor):

export class IgxForOfDirective<T, U extends NgIterable<T> = NgIterable<T>> {
    ...
    
    /**
     * Asserts the correct type of the context for the template that `igxForOf` will render.
     *
     * The presence of this method is a signal to the Ivy template type-check compiler that the
     * `IgxForOf` structural directive renders its template with a specific context type.
     */
    static ngTemplateContextGuard<T, U extends NgIterable<T>>(dir: IgxForOfDirective<T, U>, ctx: any): ctx is IgxForOfContext<T> {
        return true;
    }

@github-actions
Copy link

There has been no recent activity and this issue has been marked inactive.

@github-actions github-actions bot added the status: inactive Used to stale issues and pull requests label Dec 26, 2022
@github-actions github-actions bot closed this as completed Jan 3, 2023
@dkamburov dkamburov removed the status: inactive Used to stale issues and pull requests label Jan 3, 2023
@dkamburov dkamburov reopened this Jan 3, 2023
@github-actions
Copy link

github-actions bot commented Mar 5, 2023

There has been no recent activity and this issue has been marked inactive.

@github-actions github-actions bot added the status: inactive Used to stale issues and pull requests label Mar 5, 2023
@dkamburov dkamburov removed the status: inactive Used to stale issues and pull requests label Mar 6, 2023
@github-actions
Copy link

github-actions bot commented May 6, 2023

There has been no recent activity and this issue has been marked inactive.

@github-actions github-actions bot added the status: inactive Used to stale issues and pull requests label May 6, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2023
@zdrawku zdrawku reopened this May 15, 2023
@zdrawku zdrawku removed the status: inactive Used to stale issues and pull requests label May 15, 2023
@dkamburov dkamburov added 🛠️ status: in-development Issues and PRs with active development on them and removed 🆕 status: new labels Jun 29, 2023
@skrustev skrustev added ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged. and removed 🛠️ status: in-development Issues and PRs with active development on them labels Jul 3, 2023
radomirchev added a commit that referenced this issue Oct 20, 2023
Moving IgxForOfDirective #12182 from 16.1 to 16.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧰 feature-request virtualization ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged.
Projects
None yet
Development

No branches or pull requests

5 participants