Why does Typescript allow to assign an “any” object type to class object?

前端 未结 3 1210
感情败类
感情败类 2021-01-11 17:19

I have a class object:

groupNameData: GroupNameData = new GroupNameData();

and I have an any object

 groupNam         


        
3条回答
  •  情深已故
    2021-01-11 18:05

    TypeScript needs a different way of thinking from a traditional statically type language. In languages like C# or Java the compilar gives a type error unless the programer has provided enough information to make clear to the compiler it should not give a type error. In Typescript the compiler only gives a type error if the programer has provided enough information for the compiler to know the types are not valid.

    The use of Any takes information away from the compiler.

    Typescript was created to allow the incremental addition of type information with as many bugs in the program being found at compile as the type information allows. It can be thought of as a "super lint" that takes advantage of any type information that is provided.

    Over the years Typescript has moved closer to what people (like me) who are used to strict compile time type checked languages expect, but it great stenth is that it still, "fits in" well with Javascript.

提交回复
热议问题