Type 'string' is not assignable to type 'never'.ts(2322)

9,544 views
Skip to first unread message

Dev C

unread,
Apr 2, 2019, 11:59:56 AM4/2/19
to ang...@googlegroups.com
Hello

I have attached code in VS code which helps to generate dummy data. the basic purpose of having pagination in anguar 6 project.

this.collection.data.push(
{
id: i + 1, // here it gives error Type 'number' is not assignable to type 'never'.ts(2322)
value: "items number " + (i + 1)
}
);
}

 In above code error I slated error, the full code is at below:

import { Component } from '@angular/core';
@Component({
selector: 'app-pagination',
templateUrl: './pagination.component.html',
styleUrls: ['./pagination.component.css']
})
export class PaginationComponent {
config: any;
collection = { count: 60, data: [] };
constructor() {
//Create dummy data
for (var i = 0; i < this.collection.count; i++) {
// var id = i +1;
// var value = "items number " + (i + 1)
this.collection.data.push(
{
id: i + 1, // here it gives error Type 'number' is not assignable to type 'never'.ts(2322)
value: "items number " + (i + 1) // same here
}
);
}
this.config = {
itemsPerPage: 5,
currentPage: 1,
totalItems: this.collection.count
};
}
pageChanged(event: any){
this.config.currentPage = event;
}
}


Lucas Lacroix

unread,
Apr 2, 2019, 12:05:48 PM4/2/19
to ang...@googlegroups.com
It's just a guess, but I think it's because the "data" array within collections does not have a type. Try this:
collections = {count: 60, data: [] as any[]}

Also... Stop using "var" and use "let" instead. Variables defined by "var" are hoisted and this can have negative effects on your code.

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


--
Lucas Lacroix
Computer Scientist
System Technology Division, MEDITECH

                
Subscribe to receive emails from MEDITECH or to change email preferences.

Dev C

unread,
Apr 2, 2019, 1:21:36 PM4/2/19
to ang...@googlegroups.com
This worked, thanks Lucas
Reply all
Reply to author
Forward
0 new messages