TypeScript in Ember: Getting error while compiling


#1

Getting below error while compiling TypeScript file in Ember

TypeScript Version - 3.2.2, Ember-Cli: 3.6.1, Node: 10.13.0


#2

Are you using ember-cli-typescript, if so, what version?


#3

The first error is most likely happening because you have not added any models to the ModelRegistry and you don’t have a “catch all” to tell TS that the ModelRegistry contains string keys (and thus the type for keyof ModelRegistry is never). For each of your models, you need to add some code to add it to the ModelRegistry. See https://github.com/typed-ember/ember-cli-typescript#ember-data-lookups for more info.

For the second error, somehow the array type has lost its find method? Not exactly sure what’s happening here.


#4

TypeScript version is - 3.2.4

“typescript”: “^3.2.4”


#5

Thank You!

I am able to fix my 1st error by adding following code to @types/ember-data/index.d.ts

declare module 'ember-data/types/registries/model' {export default interface ModelRegistry { [key: string]: any; }}

But I am still fighting with second issue.


#6

Fixed the second issue also by declaring find() as given in below in - @types/ember-array/-private/enumarable.d.ts

find(predicate: (value: T, index: number, obj: Array<T>) => boolean, thisArg?: any): T;


#7

I’m specifically asking about ember-cli-typescript the library https://github.com/typed-ember/ember-cli-typescript