6

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.

1
  • the edit you rejected made the <> characters you included in your question visible - they need to be escaped or they are not visible when the markup is rendered to HTML. This is also what Murat K. mentioned in his answer. Commented Aug 22, 2017 at 22:31

3 Answers 3

15

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

2 Comments

the sentence I posted is the one it's generating for me.
I can see in your post that you copy pasted it with Array<T> but the displayed is Array that's what I meant. Nonetheless it's irrelevant for the reasoning.
1

Use [] instead of the Array type.

protected _collection: myInterface[];

If you want to use the Array type there should a tslint rule to disable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.