Generic type
For C # Programmers, Typescript generics are familiar, basically consistent design.
Type constraints
C # uses the WHERE keyword to mark type constraints, and typescript uses the extends keyword within angle brackets for the same effect.
In the following example, Iexample constrains the generics to be imyinterface and his derived class.
If used like this, it can be constrained to inherit both Classone and Classtwo types. very confusing, please pay special attention to it .
This is because the typescript type system is inherently less stringent, and the following chapters explain the Typescript type system in detail
You can also use generics as a type constraint for generics, as follows
Structure type
C # type system is mandatory, the type of the object must display a declaration. Even though two types have exactly the same structure, they are not the same type.
TypeScript the type system is structural, architectural, and hierarchical. Structures of the same type can be considered the same type.
Below is C # An example of
ClassA and the ClassB are completely different types, they are different and must show an inherited interface in order for them to be compatible.
and in TypeScript not in this way, we use the following example to prove it. ClassA ClassB examplec have signature-consistent functions, so they are compatible.
typescript means that you c#
this thing will make the code ever more changeable, if you're familiar with C # or JAVA , which may confuse you.
?
The following example does not require the class keyword and will actually produce the type.
In this example, an anonymous type is generated.
This anonymous type allows the development tool to provide auto-completion and the compiler will check. If you try to assign a value to the name of Obja, the compiler will check to tell you the error. The compiler also infers the type for the array.
Access Decorators
Typescript's access modifiers may give you a feeling of weakness, indeed. He is just a compile-time feature.
Everything in the module is private unless you add the Export keyword. Types that do not have an export keyword can only be applied within a module.
Inside the class, everything is public unless the Private keyword is added. Public is only intended to look explicit.
Typescript's access decorator is just like this, without C # internal and protected this decorator, want C # similar features to give up.
Transfer to become a reference manual for Typescript programmers (iv)