One of the libraries I'm using throw a lot of TS errors. It uses Object functions.
I had multiple TS errors:
error TS2339: Property 'random' does not exist on type 'Object'.
error TS2339: Property 'isArray' does not exist on type 'Object'.
error TS2339: Property 'defineProperties' does not exist on type 'Object'.
error TS2339: Property 'defineProperty' does not exist on type 'Object'.
So I created an Object interface and now I need to define all function used and which type is it. I'm playing with functions and object types. The Window element seems to be working, but the Object element does not.
interface Window {
Array: Object,
Object: Object,
WeakMap: Object,
Symbol: Object,
Math: Object,
}
interface Object {
random: Function,
isArray: Function,
defineProperties: Function,
defineProperty: Function,
create: Function,
keys: Function,
for: Function,
iterator: Function,
asyncIterator: Function,
}
declare var window: Window
declare var object: Object
Errors now (15 errors):
index.ts(1432,43): error TS2538: Type 'Object' cannot be used as an index type.
index.ts(1725,23): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Object' has no compatible call signatures.
Trying to use any type results in similar errors but with a lower count (7 errors):
interface Object {
[index: string]: any
}
error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Object' has no compatible call signatures.
One of the line:
if (!isValidElement(element) && ObjectHasOwnProperty.call(Object(element), 'default'))
I'm sure there is a better way of doing this.
It's a third-party library included in a JS file. I removed some TS errors with // @ts-ignore But I would need to add it on every line, which would be a pain and ts-ignore-start is not yet implemented (https://github.com/Microsoft/TypeScript/issues/19573)