[typeScript] js type derivation error

Version: 3.2.2
I have a person.js file and test.ts file, create a student class and person object in the js file, set student"s prototype to person, and then export an instance of student.
then accesses the instance of student in the test file, but ts does not have access to the properties on student"s prototype (that is, properties on person).

person.js

   

May.22,2022

you should set a Interface , such as

Interface Student {
    name:string
}

Typescrip Interface


you don't use the syntax of ts here at all.

you can write

as follows
   

there are still some problems with the limitations here. For example, the object returned by the prototype above does not actually contain the like field, but does not report an error.
so the above writing is still not recommended. It is recommended to operate fewer prototypes and use more ES6 syntax. There will be more support.

Menu