I wrote a construction similar to the one below in an Angular application (this was greatly simplified to demonstrate this problem). What would prevent a function from filterProperty()
defining in an instance item
inside a class DemoSource
?
export
a keyword is used because each construct is defined in a separate file.
export interface IProperty {
filterProperty(): string;
}
export class Demo implements IProperty {
displayName: string;
filterProperty(): string {
return this.displayName;
}
}
export class DemoSource<TItem extends IProperty> {
filterChange = new BehaviorSubject('');
filteredData: TItem[];
constructor(private service: IService<TItem>) {
this.filteredData = service.data.value.slice();
}
connect(): Observable<TItem[]> {
return Observable.merge(this.service.data).map(() => {
this.filteredData = this.service.data.value.slice().filter((item: TItem) => {
const searchStr = item.filterProperty().toLowerCase();
return searchStr.indexOf(this.filter.toLowerCase()) !== -1;
});
return filteredData;
});
}
}
When debugging at the point where it is called item.filter()
, I get the following error:
ERROR TypeError: Object doesn't support property or method 'filterProperty'
Update
Changed the contract function IProperty
from filter()
to filterProperty()
to avoid confusion.
Here is the error:

, item
, , filterProperty()
, ( proto):

:
@Injectable()
export class IdentityService implements IService<AppUser> {
users = new BehaviorSubject<Array<AppUser>>([]);
public get data(): BehaviorSubject<AppUser[]> { return this.users; }
}
export interface IService<T> {
data: BehaviorSubject<T>;
}
, API:

API :

-
- JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var Demo = (function () {
function Demo() {}
Object.defineProperty(Demo.prototype, "filter", {
get: function () { return this.displayName; },
enumerable: true,
configurable: true
});
return Demo;
}());
exports Demo = Demo;
- : Typescript/ API API
GitHub Repo -: typescript-interface-issues