Code type file verification method, storage medium, equipment and product

By introducing a type verification tool in the process of TypeScript compilation into JavaScript, using abstract syntax tree analysis to obtain interface type information, and performing verification during JavaScript operation, the problem of type information loss of TypeScript is solved, and the accurate verification of data object type information in JavaScript files is achieved, and the stability of the code is improved.

CN119987784APending Publication Date: 2025-05-13BEIJING TOPSEC NETWORK SECURITY TECH +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510204719.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-24
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

TypeScript type information is lost after being compiled into JavaScript, resulting in the inability to perform type verification at runtime. It is difficult for the existing technology to verify the type information of related data objects in JavaScript files.

Method used

In the process of compiling TypeScript files into JavaScript type files, a type verification tool is introduced to obtain interface type information through abstract syntax tree parsing, and use the target JavaScript code plug-in or whitelist type list for verification during the JavaScript type file running.

Benefits of technology

It realizes accurate verification of verification parameters in JavaScript type files, retains the verification method of the original TypeScript file, simplifies the type verification process, and improves the robustness and stability of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119987784A_ABST
    Figure CN119987784A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data verification, and particularly provides a code type file verification method, a storage medium, equipment and a product, the method can be applied to the process of compiling a TypeScript type file into a JavaScript type file, and the method comprises the steps of obtaining a to-be-verified object in the compiling process; based on the to-be-verified object, a type verification tool is determined, the type verification tool is a target JavaScript code plug-in or a white list type list, and the type verification tool is used for verifying verification parameters in the running process of the JavaScript type file, obtaining a verification result and verifying the verification result according to the verification result. The verification result represents whether the type information of the verification parameter is correct or not. According to some embodiments of the invention, accurate verification of the JavaScript type file after compiling and packaging can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data verification technology, and in particular to a method, storage medium, device and product for code type file verification. Background Art

[0002] With the continuous advancement of front-end technology, TypeScript (TS for short) as a strongly typed programming language has been increasingly used in front-end development. However, TypeScript can only provide type error prompts when writing and compiling TypeScript code. Once the TypeScript code is packaged into JavaScript (JS for short), the original type information will be lost, resulting in the inability to perform type checking at runtime.

[0003] At present, in order to solve the above problems, the existing technical solution inserts the type information of TypeScript during the conversion process into the generated JavaScript code through a code snippet that conforms to JavaScript, so that the JavaScript execution engine can obtain the type information through the code snippet, and the engine can subsequently reduce unnecessary type checks and deductions. Although the above reduces the steps required for type information verification by inserting code snippets that meet the requirements. However, in actual development, it is still impossible to implement type information verification of related data objects of TypeScript type files after compilation.

[0004] Therefore, how to provide a technical solution for a method of code type file verification with higher accuracy has become a technical problem that needs to be solved urgently. Summary of the invention

[0005] The purpose of some embodiments of the present application is to provide a method, storage medium, device and product for code type file verification. Through the technical solution of the embodiments of the present application, a type verification tool can be introduced in the process of compiling TypeScript type files into JavaScript files, so as to achieve accurate verification of related code objects in JavaScript files, which is highly practical.

[0006] In a first aspect, some embodiments of the present application provide a method for verifying a code type file, which is applied to the process of compiling a TypeScript type file into a JavaScript type file, and includes: obtaining an object to be verified during the compilation process; based on the object to be verified, determining a type verification tool, wherein the type verification tool is a target JavaScript code plug-in or a whitelist type list, and the type verification tool is used to verify verification parameters during the running of the JavaScript type file and obtain verification results, wherein the verification results represent whether the type information of the verification parameters is correct.

[0007] Some embodiments of the present application introduce a type verification tool after determining the object to be verified during the process of compiling a TypeScript type file into a JavaScript type file, and then the type verification tool can be used to verify the verification parameters in the running JavaScript type file to obtain the verification result. Some embodiments of the present application can introduce a type verification tool in advance during the compilation of the TypeScript type file, and then accurately verify its internal parameters during the running of the JavaScript type file, retaining the original TypeScript file verification, and the verification method is convenient and fast, and has high practicality.

[0008] In some embodiments, before obtaining the object to be verified in the compilation process, the method also includes: obtaining the source code of the TypeScript type file; parsing the source code to construct an abstract syntax tree corresponding to the TypeScript type file; extracting interface type information in the abstract syntax tree, wherein the interface type information participates in the verification of the object to be verified.

[0009] Some embodiments of the present application parse and construct the source code of the TypeScript type file to obtain an abstract syntax tree, and then extract the interface type information to facilitate the subsequent accurate verification of the verification parameters in the JavaScript type file.

[0010] In some embodiments, obtaining the object to be checked during the compilation process includes: traversing the nodes in the abstract syntax tree to obtain a preset check type; accessing each method function in the preset check type, and obtaining the function parameter type under each method function, wherein the function parameter type is the object to be checked.

[0011] Some embodiments of the present application determine the function parameter type by traversing the abstract syntax tree, so as to accurately traverse the objects to be checked to prevent omissions and losses.

[0012] In some embodiments, determining a type checking tool based on the object to be checked includes: inserting the target JavaScript code plug-in into the starting position of each method function.

[0013] Some embodiments of the present application can subsequently implement verification of verification parameters in JavaScript type files by inserting a target JavaScript code plug-in to obtain verification results with high accuracy.

[0014] In some embodiments, the verification result is obtained by the following method: during the execution of the JavaScript type file, the target JavaScript code plug-in confirms that the function parameter type is consistent with the interface type information, then the verification result is correct; the target JavaScript code plug-in confirms that the function parameter type is inconsistent with the interface type information, then the verification result is an error, and an error message is output, wherein the error message includes: the location of the function parameter type and the cause of the error.

[0015] Some embodiments of the present application obtain verification results by confirming whether the function parameter types are consistent with the parameters of the interface type information through a target JavaScript code plug-in during the execution of a JavaScript type file, which is both efficient and accurate.

[0016] In some embodiments, before the TypeScript type file is compiled, the method further includes: introducing an object verification class in the TypeScript type file, wherein the object verification class includes all objects to be verified and the interface type information of each object to be verified among all objects to be verified; determining the type verification tool based on the objects to be verified includes: generating the whitelist type list based on the interface type information of each object to be verified.

[0017] Some embodiments of the present application insert an object verification class into a TypeScript type file, and subsequently generate a corresponding whitelist type list based on the verification class, thereby providing a reference for verifying verification parameters during the running of the JavaScript type file and obtaining accurate verification results.

[0018] In some embodiments, the verification parameter is one of all the objects to be verified; the verification result is obtained by the following method: during the execution of the JavaScript type file, if it is confirmed that the type attribute information of the verification parameter is consistent with the content in the whitelist type list, then the verification result is correct; if it is confirmed that the type attribute information of the verification parameter is inconsistent with the content in the whitelist type list, then the verification result is an error, and the error attribute information is output.

[0019] Some embodiments of the present application determine the verification result by comparing the type attribute information of the verification parameter with the whitelist type list, which is both efficient and accurate.

[0020] In a second aspect, some embodiments of the present application provide a device for code type file verification, which is applied to the process of compiling a TypeScript type file into a JavaScript type file, and includes: an acquisition module, configured to obtain an object to be verified during the compilation process; a verification module, configured to determine a type verification tool based on the object to be verified, wherein the type verification tool is a target JavaScript code plug-in or a whitelist type list, and the type verification tool is used to verify the verification parameters during the running of the JavaScript type file and obtain the verification results, wherein the verification results represent whether the type information of the verification parameters is correct.

[0021] In a third aspect, some embodiments of the present application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can implement the method described in any embodiment of the first aspect.

[0022] In a fourth aspect, some embodiments of the present application provide an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor can implement a method as described in any embodiment of the first aspect when executing the program.

[0023] In a fifth aspect, some embodiments of the present application provide a computer program product, wherein the computer program product comprises a computer program, wherein the computer program, when executed by a processor, can implement the method described in any embodiment of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions of some embodiments of the present application, the drawings required for use in some embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0025] Figure 1 A system diagram of code type file verification provided for some embodiments of the present application;

[0026] Figure 2 One of the flow charts of the code type file verification method provided in some embodiments of the present application;

[0027] Figure 3 A second flowchart of a method for checking a code type file provided in some embodiments of the present application;

[0028] Figure 4 Flowchart 3 of a method for code type file verification provided for some embodiments of the present application;

[0029] Figure 5 A block diagram of a device for checking code type files provided in some embodiments of the present application;

[0030] Figure 6 A schematic diagram of an electronic device is provided for some embodiments of the present application. DETAILED DESCRIPTION

[0031] The technical solutions in some embodiments of the present application will be described below in conjunction with the drawings in some embodiments of the present application.

[0032] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0033] In front-end development, the introduction of TypeScript (TS) has greatly enhanced the type safety and maintainability of the code. Among them, interface, as one of the core features of TS, provides developers with a powerful way to define the shape of objects and constrain object properties. However, traditional TS type checking is only performed during the compilation phase. Once the code is packaged into JavaScript (JS), the type information will be lost, resulting in the inability to directly use this type information for verification at runtime.

[0034] In view of this, some embodiments of the present application provide a method for checking code type files, which can introduce a type checking tool into a TS type file during the process of compiling a TypeScript type file into a JavaScript type file. Specifically, the method first determines the object to be checked that needs to be checked during the compilation process; then determines the type checking tool to be introduced. Afterwards, during the operation of the JavaScript type file, the type checking tool designed by the present application is used to check the internal check parameters to obtain the check result. Some embodiments of the present application can retain the TS type check and realize timely and accurate check of the check parameters during the operation of the JavaScript type file.

[0035] Compared with traditional type verification methods, the type verification tool in this application does not require developers to manually write verification rules, which greatly simplifies the process of type verification. At the same time, since the verification rules (that is, the type verification tool) are automatically generated before compilation and can continue to play a role in the packaged JavaScript code, it can ensure that effective type verification is provided throughout the life cycle of the project, thereby reducing the risks and subsequent repair costs caused by type errors. Therefore, the type verification tool in this application has important application value in the development of TypeScript projects, providing developers with a more efficient and convenient type verification solution.

[0036] The following is combined with Figure 1 The overall composition structure of the system for code type file verification provided by some embodiments of the present application is exemplified.

[0037] like Figure 1 As shown, some embodiments of the present application provide a system diagram for code type file verification, and the system for code type file verification may include: a terminal 100 and a verification server 200. Among them, the user can select a TypeScript type file to be compiled on the terminal 100, compile and package the TypeScript type file into a JavaScript type file, and then store the JavaScript type file on the server 200. When the server 200 is accessed through the browser of the terminal 100, the JavaScript type file is run by verifying its internal verification parameters through the type verification tool introduced in the TypeScript type file, and the verification result is obtained, and the verification result is displayed on the browser side of the terminal 100.

[0038] In some embodiments of the present application, the terminal 100 is a mobile terminal, and may also be a non-portable computer terminal, which is not specifically limited in the embodiments of the present application.

[0039] The following is combined with Figure 2 The implementation process of code type file verification performed by the terminal 100 provided in some embodiments of the present application is exemplified.

[0040] Please see attached Figure 2 , Figure 2 A flow chart of a method for verifying a code type file is provided for some embodiments of the present application. The method for verifying a code type file is applied to the process of compiling a TypeScript type file into a JavaScript type file. The method for verifying a code type file may include: S210, obtaining an object to be verified during the compilation process. S220, based on the object to be verified, determining a type verification tool, wherein the type verification tool is a target JavaScript code plug-in or a whitelist type list, and the type verification tool is used to verify verification parameters during the operation of the JavaScript type file and obtain verification results, wherein the verification results represent whether the type information of the verification parameters is correct.

[0041] For example, in the process of compiling a TypeScript type file into a JavaScript type file, the terminal 100 can determine the object to be verified by traversing, and then design different type verification tools based on the object to be verified, so as to verify the compiled JavaScript type file and obtain the verification result. The method provided by the present application can retain the TS type verification in the JS file, solving the problem of TS type verification being lost after the TS file is compiled in the prior art. Among them, the type information of the object to be verified can be used as the verification basis for the verification parameters that need to be verified later.

[0042] In some embodiments of the present application, before executing S210, the method for verifying a code type file may include: obtaining the source code of the TypeScript type file; parsing the source code to construct an abstract syntax tree corresponding to the TypeScript type file; extracting interface type information in the abstract syntax tree, wherein the interface type information participates in the verification of the object to be verified.

[0043] For example, the code system preset in the terminal 100 obtains the source code of the TypeScript type file through a reading operation. Then, the built-in parser module is used to deeply analyze the source code, and the corresponding abstract syntax tree (AST) is gradually constructed, that is, the AST tree structure corresponding to the TypeScript type file code. In the process of building the AST tree, all defined interface type information introduced by the import statement is extracted to ensure that these key interface type definitions are completely extracted. Based on the interface interface, verification rules and dynamic declaration verification can be automatically generated to facilitate the subsequent effective verification of the verification parameters in the JS type file through this interface type information (or directly referred to as interface type information).

[0044] In order to improve the flexibility of type information verification, this application proposes two different types of type verification tools. In practical applications, any one of the tools can be selected based on the actual application scenario.

[0045] The following uses the type checking tool as the target JavaScript code plug-in as an example to illustrate the checking process of the object to be checked.

[0046] In some embodiments of the present application, S210 may include: traversing the nodes in the abstract syntax tree to obtain a preset verification type; accessing each method function in the preset verification type, and obtaining a function parameter type under each method function, wherein the function parameter type is the object to be verified.

[0047] For example, in some embodiments of the present application, in the process of traversing the AST tree, when traversing to the definition of the class class (as a specific example of the preset verification type), further refinement is required. At this time, the terminal 100 will access each method function in the class class one by one. By parsing each method function, the type restriction information of each method function is accurately obtained. The type restriction information can characterize the type, attribute (such as string) of the function parameter type required by each method function. The parameter type (that is, the function parameter type) passed into each method function is the object to be verified. It should be understood that the preset verification type can be other types in addition to the class class in this embodiment, and the embodiments of the present application are not limited to this.

[0048] In some embodiments of the present application, S220 may include: inserting the target JavaScript code plug-in into the starting position of each method function.

[0049] For example, in some embodiments of the present application, the system will automatically insert a section of JavaScript code (as a specific example of the target JavaScript code plug-in) at the starting position of each method function. The role of this section of JavaScript code is to serve as a type verifier (as a specific example of a type verification tool). During the operation of the JS type file, when the method function is called, the type verifier will check the parameter type (as a specific example of the verification parameter) passed into each method function one by one, whether it is completely consistent with the definition of the interface type information extracted and stored before, so as to obtain the verification result.

[0050] In some embodiments of the present application, the verification result is obtained by the following method: during the execution of the JavaScript type file: confirming through the target JavaScript code plug-in that the function parameter type is consistent with the interface type information, then the verification result is correct; confirming through the target JavaScript code plug-in that the function parameter type is inconsistent with the interface type information, then the verification result is an error, and an error message is output, wherein the error message includes: the location of the function parameter type and the cause of the error.

[0051] For example, in some embodiments of the present application, during the operation of a JS type file, if the parameter type and the interface type information are completely consistent, the verification result is successful. If the parameter type and the interface type information are not completely consistent, the verification result is an error, and the error handling mechanism is immediately triggered to print and output detailed error information through the standard output stream or log system, clearly indicating the specific location and cause of the parameter type error, so that developers can quickly locate and fix the problem.

[0052] The following uses the whitelist type list as an example to illustrate the verification process of the object to be verified.

[0053] In some embodiments of the present application, before executing S210, the method for code type file verification may include: introducing an object verification class in the TypeScript type file, wherein the object verification class includes all objects to be verified and the interface type information of each object to be verified among all objects to be verified; S220 may include: generating the whitelist type list based on the interface type information of each object to be verified.

[0054] For example, in some embodiments of the present application, a reserved JS object verification class (as a specific example of the object verification class) is introduced in the TypeScript type file, and each reserved JS object verification class corresponds to the reserved JS object (as a specific example of the object to be verified) that needs to be verified later. This JS object verification class has a unique function, that is: it can include all JS objects to be verified (as a specific example of all objects to be verified) (that is, declare the objects that need to be verified), and assign corresponding TS interface (interface) types to them (as a specific example of interface type information). When the TypeScript code is compiled into JS code, this JS object verification class will automatically generate a detailed attribute whitelist list (as a specific example of the whitelist type list), and the attribute whitelist list lists in detail the attribute names that each JS object to be verified can have, the type requirements of the attribute values, and whether these attributes are required items and other key information. With the content in the attribute whitelist list as the verification benchmark, the accurate verification of the JS object (as a specific example of the verification parameter) that needs to be verified during the operation of the JS type file is realized. That is, the verification result is determined by comparing the type attribute information of the JS object with the content in the attribute whitelist.

[0055] In some embodiments of the present application, the object to be verified is one of all the objects to be verified, and the verification result is obtained by the following method: during the execution of the JavaScript type file: if it is confirmed that the type attribute information of the verification parameter is consistent with the content in the whitelist type list, then the verification result is correct; if it is confirmed that the type attribute information of the verification parameter is inconsistent with the content in the whitelist type list, then the verification result is wrong, and the error attribute information is output.

[0056] For example, in some embodiments of the present application, during the actual operation of the JS type file compiled from the TypeScript code, whenever a new reserved JS object is declared (i.e., the JS object is characterized as a verification parameter), the JS object verification class designed above will automatically intervene, and detect the JS object through the type information recorded in the attribute whitelist list, and confirm whether the type attribute information of the JS object is consistent with the content recorded in the attribute whitelist list, such as whether the name of the attribute is correct, whether the type of the attribute value is consistent with the definition in the whitelist, and whether any required attributes are omitted. If they are consistent, the verification result is successful; if they are inconsistent, the error handling mechanism is immediately triggered, and detailed error information is printed and output through the standard output stream or log system, clearly indicating the specific location and cause of the parameter type error, so that developers can quickly locate and fix the problem.

[0057] Specifically, the verification method provided in the above application can be applied to all development projects using the Topsec-UI front-end UI framework, making it easier for developers to quickly locate and fix problems.

[0058] The following is combined with Figure 3 The specific process of code type file verification provided by some embodiments of the present application is exemplified.

[0059] Please see attached Figure 3 , Figure 3 A flow chart of a method for checking code type files provided in some embodiments of the present application. In the process of checking the code type files, a target JavaScript code plug-in is used to check the type information.

[0060] The above process is explained below as an example.

[0061] S310, obtaining source code of a TypeScript type file.

[0062] S320, parse the source code and construct an abstract syntax tree corresponding to the TypeScript type file.

[0063] S330, traverse the abstract syntax tree to extract interface type information in the abstract syntax tree.

[0064] S340, when it is confirmed that the preset verification type is traversed, each method function in the preset verification type is accessed, and the function parameter type under each method function is obtained.

[0065] S350, inserting the target JavaScript code plug-in into the starting position of each method function.

[0066] Among them, the TypeScript type file obtains the JS type file after completing the above compilation process.

[0067] S360, during the running of the JS type file, when the method function is called, the target JavaScript code plug-in is used to determine whether the function parameter type is consistent with the interface type information. If they are consistent, S370 is executed, otherwise S380 is executed.

[0068] S370, confirm that the verification result is successful.

[0069] S380, confirming that the verification result is wrong, and outputting an error message.

[0070] It can be understood that the specific implementation process of S310~S380 can refer to the method embodiment provided above. To avoid repetition, some descriptions are omitted here.

[0071] The following is combined with Figure 4 The specific process of code type file verification provided by some embodiments of the present application is exemplified.

[0072] Please see attached Figure 4 , Figure 4 A flowchart of a method for verifying a code type file is provided for some embodiments of the present application. In the process of verifying the code type file, a whitelist type list is used to verify the type information.

[0073] The above process is explained below as an example.

[0074] S410, obtaining source code of a TypeScript type file.

[0075] S420, parsing the source code and constructing an abstract syntax tree corresponding to the TypeScript type file.

[0076] S430, traverse the abstract syntax tree to extract interface type information in the abstract syntax tree.

[0077] S440, inserting an object verification class into the TypeScript type file, and generating a whitelist type list based on the interface type information of each object to be verified.

[0078] S450, obtaining a reserved JS object during the running of the JS type file.

[0079] S460, determine whether the type attribute information of the reserved JS object is consistent with the content in the whitelist type list, if so, execute S470, otherwise execute S480.

[0080] S470, confirming that the verification result is successful.

[0081] S580, confirming that the verification result is an error, and outputting an error message.

[0082] It can be understood that the specific implementation process of S410 to S480 can refer to the method embodiment provided above. To avoid repetition, some descriptions are omitted here.

[0083] It can be seen from some embodiments of the present application described above that the present application can ensure that the JS object (i.e., the object to be verified) strictly complies with the predefined interface specifications during declaration and use through an automated attribute verification mechanism. This greatly reduces runtime errors caused by mismatched attribute types or missing required attributes, thereby improving the robustness and stability of the code. When developers write code, there is no need to manually check whether the attributes of each JS object meet the requirements. The present application implements automatic verification, which not only saves development time, but also reduces the possibility of errors, allowing developers to focus more on the implementation of business logic. With the continuous development of the project, the code base may become large and complex. The method of the present invention makes the code structure clearer, easier to understand and maintain by providing clear interface specifications and attribute verification mechanisms. Even if new members join the project, they can quickly get started and follow the established specifications. In a team development environment, different developers may be responsible for different modules or functions. The method of the present invention promotes collaboration and communication between team members by ensuring that all JS objects follow a unified interface specification. Although TypeScript itself has the ability of static type checking, in some cases, developers may need to perform type checking at runtime. The method of the present invention provides a flexible way to enable developers to enable dynamic type checking when needed, thereby further enhancing the security and reliability of the code.

[0084] Please refer to Figure 5 , Figure 5 The following is a block diagram of a device for checking code type files provided by some embodiments of the present application. It should be understood that the device for checking code type files corresponds to the above method embodiment and can perform each step involved in the above method embodiment. The specific functions of the device for checking code type files can be found in the above description. To avoid repetition, the detailed description is appropriately omitted here.

[0085] Figure 5 The device for checking code type files includes at least one software function module that can be stored in a memory in the form of software or firmware or solidified in the device for checking code type files. The device for checking code type files is applied to the process of compiling TypeScript type files into JavaScript type files, including: an acquisition module 510, configured to obtain an object to be checked during the compilation process; a verification module 520, configured to determine a type verification tool based on the object to be checked, wherein the type verification tool is a target JavaScript code plug-in or a whitelist type list, and the type verification tool is used to verify the verification parameters during the running of the JavaScript type file and obtain the verification result, and the verification result represents whether the type information of the verification parameter is correct.

[0086] In some embodiments of the present application, before obtaining module 510, the device for verifying the code type file also includes an extraction module (not shown in the figure), which is configured to obtain the source code of the TypeScript type file; parse the source code to construct an abstract syntax tree corresponding to the TypeScript type file; extract interface type information in the abstract syntax tree, wherein the interface type information participates in the verification of the object to be verified.

[0087] In some embodiments of the present application, the acquisition module 510 is configured to traverse the nodes in the abstract syntax tree to obtain a preset verification type; access each method function in the preset verification type, and obtain the function parameter type under each method function, wherein the function parameter type is the object to be verified.

[0088] In some embodiments of the present application, the verification module 520 is configured to insert the target JavaScript code plug-in into the starting position of each method function.

[0089] In some embodiments of the present application, the verification module 520 is configured to, during the execution of the JavaScript type file, confirm through the target JavaScript code plug-in that the function parameter type is consistent with the interface type information, and the verification result is correct; if it is confirmed through the target JavaScript code plug-in that the function parameter type is inconsistent with the interface type information, the verification result is an error, and an error message is output, wherein the error message includes: the location of the function parameter type and the cause of the error.

[0090] In some embodiments of the present application, before obtaining module 510, the device for verifying the code type file also includes an introduction module (not shown in the figure), which is configured to introduce an object verification class in the TypeScript type file, wherein the object verification class includes all objects to be verified and the interface type information of each object to be verified among all objects to be verified; the verification module 520 is configured to generate the whitelist type list based on the interface type information of each object to be verified.

[0091] In some embodiments of the present application, the verification module 520 is configured to, during the running process of the JavaScript type file, if it is confirmed that the type attribute information of the verification parameter is consistent with the content in the whitelist type list, then the verification result is correct; if it is confirmed that the type attribute information of the verification parameter is inconsistent with the content in the whitelist type list, then the verification result is wrong and the error attribute information is output.

[0092] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method, and will not be described in detail here.

[0093] Some embodiments of the present application further provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can implement the operations of the method corresponding to any of the above methods provided in the above embodiments.

[0094] Some embodiments of the present application further provide a computer program product, which includes a computer program, wherein when the computer program is executed by a processor, it can implement the operations corresponding to any of the above methods provided in the above embodiments.

[0095] like Figure 6 As shown, some embodiments of the present application provide an electronic device 600, which includes: a memory 610, a processor 620, and a computer program stored in the memory 610 and executable on the processor 620, wherein the processor 620 can implement a method as described in any of the above embodiments when reading the program from the memory 610 through a bus 630 and executing the program.

[0096] Processor 620 can process digital signals and can include various computing structures, such as complex instruction set computer structure, reduced instruction set computer structure, or a structure that implements a combination of multiple instruction sets. In some examples, processor 620 can be a microprocessor.

[0097] The memory 610 may be used to store instructions executed by the processor 620 or data related to the execution of instructions. These instructions and / or data may include codes for implementing some or all functions of one or more modules described in the embodiments of the present application. The processor 620 of the disclosed embodiment may be used to execute instructions in the memory 610 to implement the method shown above. The memory 610 includes a dynamic random access memory, a static random access memory, a flash memory, an optical memory, or other memory known to those skilled in the art.

[0098] The above description is only an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application. It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings.

[0099] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0100] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

Claims

1. A method for checking a code type file, characterized in that: The method is applied to a process of compiling a TypeScript type file into a JavaScript type file, and the method comprises: Get the object to be verified during the compilation process; Based on the object to be checked, a type checking tool is determined, wherein the type checking tool is a target JavaScript code plug-in or a whitelist type list, and the type checking tool is used to check the checking parameters during the running of the JavaScript type file and obtain the checking result, wherein the checking result indicates whether the type information of the checking parameters is correct.

2. The method according to claim 1, characterized in that Before obtaining the object to be verified in the compiling process, the method further includes: Obtain the source code of the TypeScript type file; Parsing the source code to construct an abstract syntax tree corresponding to the TypeScript type file; Extracting interface type information from the abstract syntax tree, wherein the interface type information participates in the verification of the object to be verified.

3. The method according to claim 2, characterized in that The obtaining of the object to be verified during the compilation process includes: Traversing the nodes in the abstract syntax tree to obtain preset verification types; Access each method function in the preset verification type, and obtain the function parameter type under each method function, wherein the function parameter type is the object to be verified.

4. The method according to claim 3, characterized in that The step of determining a type verification tool based on the object to be verified includes: The target JavaScript code plug-in is inserted into the starting position of each method function.

5. The method according to claim 4, characterized in that The verification result is obtained by the following method: during the execution of the JavaScript type file, If the target JavaScript code plug-in confirms that the function parameter type is consistent with the interface type information, the verification result is correct; If it is confirmed through the target JavaScript code plug-in that the function parameter type is inconsistent with the interface type information, the verification result is an error and an error message is output, wherein the error message includes: the location of the function parameter type and the cause of the error.

6. The method according to claim 2, characterized in that Before compiling the TypeScript type file, the method further includes: Introducing an object verification class in the TypeScript type file, wherein the object verification class includes all objects to be verified and the interface type information of each object to be verified among all objects to be verified; The step of determining a type verification tool based on the object to be verified includes: Based on the interface type information of each object to be verified, the whitelist type list is generated.

7. The method according to claim 6, characterized in that The verification parameter is one of all the objects to be verified; the verification result is obtained by the following method: during the execution of the JavaScript type file, If it is confirmed that the type attribute information of the verification parameter is consistent with the content in the whitelist type list, the verification result is correct; If it is confirmed that the type attribute information of the verification parameter is inconsistent with the content in the whitelist type list, the verification result is an error, and the error attribute information is output.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program executes the method according to any one of claims 1 to 7 when executed by a processor.

9. An electronic device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the computer program executes the method according to any one of claims 1 to 7 when being run by the processor.

10. A computer program product, characterized in that The computer program product comprises a computer program, wherein the computer program executes the method according to any one of claims 1 to 7 when executed by a processor.