I have a question about the following use of a typescript array. It all works fine but when I run it through the linter I get the following error, my assignment is obviously wrong.
Array type using 'Array' is forbidden for simple types. Use 'T[]' instead.
export let data = [
{
"property": "value"
}
];
export interface myInterface {
property: string;
};
protected _collection: Array<myInterface>;
Any assistance is appreciated.
The linter probably just wants you to do:
protected _collection: myInterface[];
The types myInterface[]
and Array<myInterface>
are equivalent, but the linter seems to prefer the first.
Seems like the error stacktrace is not complete. The complete sentence is
Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
You have to code format it on SO. And the reason for the linter is here in the source code of palantir
https://github.com/palantir/tslint/blob/master/src/rules/arrayTypeRule.ts#L81-L82
They want you to avoid using Array<T>
in general. Instead you have to use it like this
protected _collection: myInterface[];
This is more like a preference from them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With