question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error TS2339: Property 'name' does not exist on type 'unknown'

See original GitHub issue

Hi,

When I try to build (with Ivy) the example “Custom template for all selected items using ng-multi-label-tmp” I’ve got this error : error TS2339: Property 'avatar_url' does not exist on type 'unknown'

If I disable Ivy, it compiles. Is there a way to allow this example to compile ? It seems like let-items=“items” in the declaration of ng-multi-label-tmp doesn’t keep the type of [items]

I use this example in my project and would like to build it using Ivy. Here is my code :

<div class="col-12 col-sm-6 col-md-4 col-xl p-2" *ngFor="let filter of filters">
    <ng-select
        [placeholder]="filter.name"
        [items]="filter.items"
        bindLabel="name"
        bindValue="filter"
        groupBy="groupValue"
        [selectableGroup]="true"
        [selectableGroupAsModel]="false"
        [multiple]="true"
        [closeOnSelect]="false"
        (change)="applyChange()"
        [(ngModel)]="userSelections[filter.name]"
        class="input-xs"
        >
        <ng-template ng-optgroup-tmp let-item="item">
            {{item.groupValue || ''}}
        </ng-template>
        <ng-template ng-option-tmp let-item="item" let-item$="item$" let-index="index">
            <input id="item-{{index}}" type="checkbox" [ngModel]="item$.selected"/> {{item.name}}
        </ng-template>
        <ng-template ng-multi-label-tmp let-items="items" let-clear="clear">
            <div class="ng-value" *ngFor="let item of items | slice:0:filter.maxItems">
                <span *ngIf="items.length < filter.maxItems">
                <span class="ng-value-label">{{item.name}}</span>
                <span class="ng-value-icon right" (click)="clear(item)" aria-hidden="true">×</span>
                </span>
            </div>
            <div class="ng-value" *ngIf="items.length > filter.maxItems">
                <span class="ng-value-label">{{items.length - filter.maxItems}} de plus...</span>0
            </div>
        </ng-template>
    </ng-select>
</div>

Thanks for your help.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:5

github_iconTop GitHub Comments

7reactions
promoter0100commented, Feb 8, 2021

Same here, any updates on this? Btw if someone is struggling with this, dirty solution would be usage of {{$any(item).name}}. It will make compiler happy again.

example:

<ng-select [multiple]="true" [items]="cities" formControlName="city"
   [closeOnSelect]="false" placeholder="Select city" bindLabel="name" bindValue="id">
      <ng-template ng-multi-label-tmp let-items="items" let-clear="clear">
          <div class="ng-value" *ngFor="let item of items | slice:0:2">
              <span class="ng-value-label"> {{$any(item).name}}</span>
              <span class="ng-value-icon right" (click)="clear(item)" aria-hidden="true">×</span>
          </div>
          <div class="ng-value" *ngIf="items.length > 2">
              <span class="ng-value-label">{{items.length - 2}} more...</span>
          </div>
      </ng-template>
</ng-select>

you can try item[“name”]. I don’t know but it’s works

6reactions
Exerlolcommented, Jan 20, 2021

Same here, any updates on this? Btw if someone is struggling with this, dirty solution would be usage of {{$any(item).name}}. It will make compiler happy again.

example:

<ng-select [multiple]="true" [items]="cities" formControlName="city"
   [closeOnSelect]="false" placeholder="Select city" bindLabel="name" bindValue="id">
      <ng-template ng-multi-label-tmp let-items="items" let-clear="clear">
          <div class="ng-value" *ngFor="let item of items | slice:0:2">
              <span class="ng-value-label"> {{$any(item).name}}</span>
              <span class="ng-value-icon right" (click)="clear(item)" aria-hidden="true">×</span>
          </div>
          <div class="ng-value" *ngIf="items.length > 2">
              <span class="ng-value-label">{{items.length - 2}} more...</span>
          </div>
      </ng-template>
</ng-select>
Read more comments on GitHub >

github_iconTop Results From Across the Web

error TS2339: Property 'x' does not exist on type 'Y'
I'm getting error (using TypeScript 1.7.5):. error TS2339: Property 'main' does not exist on type 'Images'. Of course I could get rid of...
Read more >
Property does not exist on type 'unknown'. : r/typescript - Reddit
The error is telling you that you have a value of type unknown , but you are trying to assign it to a...
Read more >
How to resolve the error ' Error:(54,6) TS2339:property 'name ...
FIrst - what the error message means - It means that the object doesn't have a property(field/attribute/variable) or method(function) by that name at...
Read more >
Typescript Type System: How Does it Really Work? Type ...
Let's have a look at the error message we get: Error:(54, 6) TS2339:Property 'name' does not exist on type '{}'. So what is ......
Read more >
Fix - Property does not exist on type '{}' in TypeScript
To fix the error “Property does not exist on type '{}'” in Typescript and when working with node, remember to access only object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found