CN117406969A - Method, system, device and medium for generating TypeScript type statement - Google Patents

Method, system, device and medium for generating TypeScript type statement Download PDF

Info

Publication number
CN117406969A
CN117406969A CN202310786658.9A CN202310786658A CN117406969A CN 117406969 A CN117406969 A CN 117406969A CN 202310786658 A CN202310786658 A CN 202310786658A CN 117406969 A CN117406969 A CN 117406969A
Authority
CN
China
Prior art keywords
file
json
typescript
type
character string
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310786658.9A
Other languages
Chinese (zh)
Inventor
张健
杨泉林
盛建鲁
魏文凤
贾立娟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Intelligent Technology Co Ltd
Original Assignee
Inspur Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Intelligent Technology Co Ltd filed Critical Inspur Intelligent Technology Co Ltd
Priority to CN202310786658.9A priority Critical patent/CN117406969A/en
Publication of CN117406969A publication Critical patent/CN117406969A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)

Abstract

The invention provides a generation method, a system, a device and a medium of a TypeScript type statement, wherein the method comprises the following steps: creating a json format file according to development requirements, and defining data in the json format file to generate a json data file; analyzing the json data file to generate a json object; generating a corresponding TypeScript type definition character string according to different field types in the json object; and writing the generated TypeScript type definition character string into a preset file, and storing the TypeScript type definition character string into a file in a ts format. The invention can quickly convert the needed json format file into the ts type file, improves the development efficiency of developers, and can derive the corresponding file to support direct use in projects.

Description

Method, system, device and medium for generating TypeScript type statement
Technical Field
The invention relates to the technical field of computers, in particular to a method, a system, a device and a medium for generating a TypeScript type statement.
Background
TypeScript is an open-source programming language built by adding static type definitions on the basis of JavaScript. TypeScript is translated into JavaScript code by a TypeScript compiler or Babel, and can run on any browser, any operating system. TypeScript adds many new properties (e.g., decorators) of ECMAScript that have not yet been formally released.
TypeScript is an open source front-end scripting language. It is a strict grammatical superset of JavaScript, with optional static types added. It is specifically designed for developing large applications and can be compiled into JavaScript. Among the wide-ranging applications of TypeScript and the development of front-end projects, the benefits of using TypeScript for front-end project development mainly include the following: (1) The readability and maintainability of codes are enhanced, a strong type of system is equivalent to the best document, most errors can be found during compiling, and the functions of an editor are enhanced. (2) The inclusion, js file can be changed into ts file directly, undefined type can deduce the type automatically, can define almost all types, ts can also generate js file when ts is compiled and reported wrong, is compatible with third party library, even if not written with ts (3) has active community, most of third party library can be provided for ts type definition file, and completely supports es6 specification.
Currently, in the front-end TypeScript development project process, a large number of ts type declarations need to be defined, types of various fields of a required object are specified, the traditional implementation process is that a developer manually writes each type definition, the process is tedious and easy to make mistakes, and development efficiency of the developer is reduced.
Disclosure of Invention
Aiming at the problems, the invention aims to provide a method, a system, a device and a medium for generating a TypeScript type statement, which can quickly convert a needed json format file into a ts type file, improve the development efficiency of developers, and can lead out the corresponding file to support direct use in a project.
The invention aims to achieve the aim, and the aim is achieved by the following technical scheme:
in a first aspect, the present invention discloses a method for generating a TypeScript type statement, including:
creating a json format file according to development requirements, and defining data in the json format file to generate a json data file;
analyzing the json data file to generate a json object;
generating a corresponding TypeScript type definition character string according to different field types in the json object;
and writing the generated TypeScript type definition character string into a preset file, and storing the TypeScript type definition character string into a file in a ts format.
Further, the json format file includes data of a character string type, data of a numerical type, data of an object type, and data of a data type.
Further, the parsing the json data file to generate json objects includes:
invoking an fs file processing module under nodejs;
and reading and analyzing the content of the json data file by using a fs.readfile () method to generate a corresponding json object.
Further, the generating the corresponding TypeScript type definition string according to the different field types in the json object includes:
when the field value in the json object is a character string, generating and returning a character string type string;
when the field value in the json object is a numerical value, a numerical value type number is generated and returned.
Further, the generating the corresponding TypeScript type definition string according to the different field types in the json object further includes:
identifying each field in the json object by way of recursive processing when the field value in the json object is the object, until the identified field value is a string or a numeric value;
when the field value in the json object is an array, identifying element content in the array;
if the element content is a character string, generating and returning a character string array type string [ ]; if the element content is a numerical value, generating and returning a numerical value array type number [ ]; if the element content is the object element, identifying each field in the object element in a recursion processing mode, ending until the identified field value is a character string or a numerical value, and generating and returning object type data after the processing is completed.
Further, the generating the corresponding TypeScript type definition string according to the different field types in the json object further includes:
if the field type name and namespace in the json object have been specified, then a corresponding declaration is added in front of the generated TypeScript type definition string.
Further, writing the generated TypeScript type definition character string into a preset file, and storing the TypeScript type definition character string as a file in a ts format, including:
writing the generated TypeScript type definition character string into a preset file by using a writeFile () method of the fs file processing module;
the file path of the output file is specified and saved as a file in ts format.
In a second aspect, the present invention also discloses a system for generating a TypeScript type statement, including:
the file definition unit is configured to create a json format file according to development requirements and define data in the json format file so as to generate a json data file;
the file analysis unit is configured to analyze the json data file and generate a json object;
the type definition character string generation unit is configured to generate a corresponding TypeScript type definition character string according to different field types in the json object;
and the storage unit is configured to write the generated TypeScript type definition character string into a preset file and store the TypeScript type definition character string as a file in a ts format.
Further, the file parsing unit is specifically configured to: invoking an fs file processing module under nodejs; and reading and analyzing the content of the json data file by using a fs.readfile () method to generate a corresponding json object.
Further, the type definition string generation unit is specifically configured to:
when the field value in the json object is a character string, generating and returning a character string type string;
when the field value in the json object is a numerical value, generating and returning a numerical value type number;
identifying each field in the json object by way of recursive processing when the field value in the json object is the object, until the identified field value is a string or a numeric value;
when the field value in the json object is an array, identifying element content in the array; if the element content is a character string, generating and returning a character string array type string [ ]; if the element content is a numerical value, generating and returning a numerical value array type number [ ]; if the element content is the object element, identifying each field in the object element in a recursion processing mode until the identified field value is a character string or a numerical value, and generating and returning object type data after the processing is completed;
if the field type name and namespace in the json object have been specified, then a corresponding declaration is added in front of the generated TypeScript type definition string.
Further, the storage unit is specifically configured to: writing the generated TypeScript type definition character string into a preset file by using a writeFile () method of the fs file processing module; the file path of the output file is specified and saved as a file in ts format.
In a third aspect, the present invention also discloses a TypeScript type declaration generating device, including:
a memory for storing a generator of a TypeScript type declaration;
and the processor is used for realizing the steps of the TypeScript type declaration generation method when executing the TypeScript type declaration generation program.
In a fourth aspect, the present invention also discloses a readable storage medium, where a TypeScript type declaration generation program is stored, where the TypeScript type declaration generation program, when executed by a processor, implements the steps of the TypeScript type declaration generation method according to any one of the above.
Compared with the prior art, the invention has the beneficial effects that: the invention discloses a generation method, a system, a device and a readable storage medium of a TypeScript type statement, which are used for analyzing a json data file required by a development project into a json object by defining the file, generating a corresponding TypeScript type definition character string according to different field types in the object, and adding a corresponding statement in front of the type definition character string when a type name and a naming space are required to be specified. Finally, the generated type definition string write file is saved as a ts file. The invention realizes automatic generation of TypeScript type statement, writes the generated type definition character string into the file and saves the file as the ts file, supports direct import project use, reduces the error probability in the process of writing the type statement, and improves the development efficiency of developers.
It can be seen that the present invention has outstanding substantial features and significant advances over the prior art, as well as the benefits of its implementation.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required to be used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only embodiments of the present invention, and that other drawings can be obtained according to the provided drawings without inventive effort for a person skilled in the art.
FIG. 1 is a method flow diagram of a method for generating a TypeScript type statement in an embodiment of the invention.
FIG. 2 is a system architecture diagram of a TypeScript type declaration generation system in accordance with an embodiment of the invention.
Fig. 3 is a schematic structural diagram of a TypeScript type declaration generating device in an embodiment of the present invention.
In the figure, 1, a file definition unit; 2. a file analysis unit; 3. a type definition character string generation unit; 4. a storage unit; 101. a processor; 102. a memory; 103. an input interface; 104. an output interface; 105. a communication unit; 106. a keyboard; 107. a display; 108. and a mouse.
Detailed Description
The core of the invention is to provide a generation method of TypeScript type declarations, in the related technology, a large number of ts type declarations need to be defined in the front-end TypeScript development project process, the types of various fields of required objects are specified, the traditional implementation process is that developers write each type definition manually, the process is tedious and easy to make mistakes, and the development efficiency of the developers is reduced.
The TypeScript type statement is generated by creating a json format file according to development requirements, and defining data in the json format file to generate a json data file. Then, the json data file is parsed to generate json objects. At this time, corresponding TypeScript type definition strings are generated according to different field types in the json object. And finally, writing the generated TypeScript type definition character string into a preset file, and storing the typeScript type definition character string as a file in a ts format. Therefore, the invention can quickly convert the needed json format file into the ts type file, improves the development efficiency of developers, and can derive the corresponding file to support direct use in the project.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
The following explains key terms appearing in the present invention.
TypeScript, an open-source programming language developed by microsoft, is built by adding static type definitions on the basis of JavaScript.
JSON (JavaScript Object Notation, JS object numbered musical notation) is a lightweight data exchange format. It stores and presents data in a text format that is completely independent of the programming language based on a subset of ECMAScript (European Computer Manufacturers Association, js specification by the european computer institute). The compact and clear hierarchical structure makes JSON an ideal data exchange language. Is easy to read and write by people, is easy to analyze and generate by machines, and effectively improves the network transmission efficiency.
In order to better understand the aspects of the present invention, the present invention will be described in further detail with reference to the accompanying drawings and detailed description. It will be apparent that the described embodiments are only some, but not all, embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Referring to fig. 1, the present embodiment provides a method for generating a TypeScript type statement, in which a development language uses TypeScript, supports web-side and mobile-side references, and a tool library uses nodejs.
The method specifically comprises the following steps:
s1: creating a json format file according to development requirements, and defining data in the json format file to generate a json data file.
The json format file comprises character string type data, numerical value type data, object type data and data type data.
As an example, first, a json format file is created, and data required by the user is defined, and the data is assumed to be:
it can be seen that the json format file contains four types of data, namely character strings, values, objects and arrays.
S2: and analyzing the json data file to generate a json object.
Specifically: firstly, invoking an fs file processing module under nodejs; and then reading and analyzing the content of the json data file by using an fs.readfile () method to generate a corresponding json object.
S3: and generating a corresponding TypeScript type definition character string according to different field types in the json object.
In a specific embodiment, the generating process of the step specifically includes the following cases:
1. when the field value in the json object is a character string, a character string type string is generated and returned.
2. When the field value in the json object is a numerical value, a numerical value type number is generated and returned.
3. When a field value in a json object is an object, each field in the object is identified by way of recursive processing until the identified field value is a string or a numeric value.
4. When the field value in the json object is an array, identifying element content in the array; if the element content is a character string, generating and returning a character string array type string [ ]; if the element content is a numerical value, generating and returning a numerical value array type number [ ]; if the element content is the object element, identifying each field in the object element in a recursion processing mode, ending until the identified field value is a character string or a numerical value, and generating and returning object type data after the processing is completed.
5. If the field type name and namespace in the json object have been specified, then a corresponding declaration is added in front of the generated TypeScript type definition string.
As an example, this step employs different processing logic according to the parsed field types, specifically as follows:
and when the field value is a character string, returning to the character string type string.
And when the field value is a numerical value, returning the numerical value type number.
When the field value is an object, the recursive processing of each field of the object is continued until the end when the field value is a string or a numeric value.
When the field value is an array, the string type string is returned when the content in the field value is a character string, and the number type number is returned when the content in the field value is a numerical value.
The data returned after the json file data processing is completed according to the processing logic above is as follows:
in some embodiments, complex json file content needs to be processed as such, and the json file content is also parsed by the fs file processing module. The complex data is assumed to be:
as the data is complex data, friends is an array, the element content is composed of objects, each object element also comprises a character string, a numerical value and an object, the processing mode is to recursively process each element object, and the processing result is an object type array as follows:
for the string and object elements contained in the hobbies array, the processing result is a string type array and an object type array, which are specifically as follows:
s4: and writing the generated TypeScript type definition character string into a preset file, and storing the TypeScript type definition character string into a file in a ts format.
In a specific embodiment, writing the generated TypeScript type definition character string into a preset file by using a writeFile () method of an fs file processing module; the file path of the output file is specified and saved as a file in ts format.
The invention provides a generation method of a TypeScript type statement, which realizes automatic generation of the TypeScript type statement. In the execution process, a developer only needs to pay attention to the aspect of data, define a json data file required by the developer, analyze the file into a json object, generate a corresponding typescript type definition character string according to different field types in the object, and for the type name and the name space required to be specified, add a corresponding statement in front of the type definition character string, and store the generated type definition character string write file as a ts file. Because the ts file supports direct import project use, the error probability in the writing type declaration process is effectively reduced, and the development efficiency of developers is improved.
Referring to fig. 2, the invention also discloses a system for generating a TypeScript type statement, which comprises: a file definition unit 1, a file parsing unit 2, a type definition character string generation unit 3 and a saving unit 4.
And the file definition unit 1 is configured to create a json format file according to development requirements and define data in the json format file to generate a json data file. The json format file comprises character string type data, numerical value type data, object type data and data type data.
The file parsing unit 2 is configured to parse the json data file to generate a json object.
In a specific embodiment, the file parsing unit 2 is specifically configured to: invoking an fs file processing module under nodejs; and reading and analyzing the content of the json data file by using a fs.readfile () method to generate a corresponding json object.
And a type definition character string generating unit 3 configured to generate a corresponding TypeScript type definition character string according to different field types in the json object.
In the specific embodiment, the type definition string generation unit 3 is specifically configured to:
when the field value in the json object is a character string, generating and returning a character string type string;
when the field value in the json object is a numerical value, generating and returning a numerical value type number;
identifying each field in the json object by way of recursive processing when the field value in the json object is the object, until the identified field value is a string or a numeric value;
when the field value in the json object is an array, identifying element content in the array; if the element content is a character string, generating and returning a character string array type string [ ]; if the element content is a numerical value, generating and returning a numerical value array type number [ ]; if the element content is the object element, identifying each field in the object element in a recursion processing mode until the identified field value is a character string or a numerical value, and generating and returning object type data after the processing is completed;
if the field type name and namespace in the json object have been specified, then a corresponding declaration is added in front of the generated TypeScript type definition string.
And a storage unit 4 configured to write the generated TypeScript type definition string into a preset file and store the TypeScript type definition string as a file in a ts format.
In a specific embodiment, the storage unit 4 is specifically configured to:
writing the generated TypeScript type definition character string into a preset file by using a writeFile () method of the fs file processing module; the file path of the output file is specified and saved as a file in ts format.
Therefore, the invention provides a system for generating TypeScript type statement, which can read the file in the json format and analyze the file into json objects; generating a corresponding typescript type definition character string according to different field types of the parsed json object; designating a type name and a name space, and adding a corresponding statement in front of the generated type definition character string; and writing the generated type definition character string into a file for storage. The system can quickly convert the needed json format file into the ts type file, improves the development efficiency of developers, and can derive the corresponding file to support direct use in projects.
Referring to fig. 3, the invention also discloses a TypeScript type declaration generating device, which comprises a processor 101 and a memory 102; the processor 101 executes the generation program of the TypeScript type statement stored in the memory, and performs the following steps:
1. creating a json format file according to development requirements, and defining data in the json format file to generate a json data file.
2. And analyzing the json data file to generate a json object.
3. And generating a corresponding TypeScript type definition character string according to different field types in the json object.
4. And writing the generated TypeScript type definition character string into a preset file, and storing the TypeScript type definition character string into a file in a ts format.
The generation device of the TypeScript type statement provided in the embodiment may include, but is not limited to, a smart phone, a tablet computer, a notebook computer, a desktop computer, or the like.
Processor 101 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 101 may be implemented in at least one hardware form of digital signal processing (Digital Signal Processor, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), programmable logic array (Programmable Logic Array, PLA). The processor 101 may also include a main processor and a coprocessor, the main processor being a processor for processing data in an awake state, also referred to as a central processor (Central Processing Unit, CPU); a coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 101 may be integrated with an image processor (Graphics Processing Unit, GPU) for use in connection with rendering and rendering of content to be displayed by the display screen. In some embodiments, the processor 101 may also include an artificial intelligence (Artificial Intelligence, AI) processor for processing computing operations related to machine learning.
Memory 102 may include one or more computer-readable storage media, which may be non-transitory. Memory 102 may also include high-speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In this embodiment, the memory 102 is at least configured to store a computer program, where the computer program, when loaded and executed by the processor 101, is capable of implementing the relevant steps of the TypeScript type declaration generation method disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 102 may also include an operating system, data, and the like, and the storage manner may be transient storage or permanent storage. The operating system may include Windows, unix, linux, among others. The data may include, but is not limited to, data involved in the generation method of the TypeScript type declaration described above, and the like.
In a specific embodiment, when the processor 101 executes the computer program stored in the memory 102, the following steps may be specifically implemented: invoking an fs file processing module under nodejs; and reading and analyzing the content of the json data file by using a fs.readfile () method to generate a corresponding json object.
In a specific embodiment, when the processor 101 executes the computer program stored in the memory 102, the following steps may be specifically implemented: when the field value in the json object is a character string, generating and returning a character string type string; when the field value in the json object is a numerical value, a numerical value type number is generated and returned.
In a specific embodiment, when the processor 101 executes the computer program stored in the memory 102, the following steps may be specifically implemented:
identifying each field in the json object by way of recursive processing when the field value in the json object is the object, until the identified field value is a string or a numeric value;
when the field value in the json object is an array, identifying element content in the array;
if the element content is a character string, generating and returning a character string array type string [ ]; if the element content is a numerical value, generating and returning a numerical value array type number [ ]; if the element content is the object element, identifying each field in the object element in a recursion processing mode, ending until the identified field value is a character string or a numerical value, and generating and returning object type data after the processing is completed.
In a specific embodiment, when the processor 101 executes the computer program stored in the memory 102, the following steps may be specifically implemented: if the field type name and namespace in the json object have been specified, then a corresponding declaration is added in front of the generated TypeScript type definition string.
In a specific embodiment, when the processor 101 executes the computer program stored in the memory 102, the following steps may be specifically implemented: writing the generated TypeScript type definition character string into a preset file by using a writeFile () method of the fs file processing module; the file path of the output file is specified and saved as a file in ts format.
Further, the generation device of the TypeScript type statement in this embodiment may further include:
an input interface 103, configured to obtain a generation program of an externally imported TypeScript type statement, store the obtained generation program of the TypeScript type statement in the memory 102, and further obtain various instructions and parameters transmitted by an external terminal device, and transmit the various instructions and parameters to the processor 101, so that the processor 101 uses the various instructions and parameters to develop corresponding processing. In this embodiment, the input interface 103 may specifically include, but is not limited to, a USB interface, a serial interface, a voice input interface, a fingerprint input interface, a hard disk reading interface, and the like.
And an output interface 104 for outputting various data generated by the processor 101 to a terminal device connected thereto, so that other terminal devices connected to the output interface can acquire various data generated by the processor 101. In this embodiment, the output interface 104 may specifically include, but is not limited to, a USB interface, a serial interface, and the like.
And the communication unit 105 is used for establishing remote communication connection between the server operation service optimizing configuration device and the external server so that the generation device of the TypeScript type statement can mount the image file in the external server. In this embodiment, the communication unit 105 may specifically include, but is not limited to, a remote communication unit based on a wireless communication technology or a wired communication technology.
A keyboard 106 for acquiring various parameter data or instructions inputted by a user by tapping the key cap in real time.
And a display 107, configured to display, in real time, information related to a generation process of running the TypeScript type declaration.
The mouse 108 may be used to assist the user in inputting data and to simplify the user's operation.
Therefore, the invention provides a TypeScript type statement generating device, which analyzes a json data file required by a development project into a json object by defining the file, generates a corresponding TypeScript type definition character string according to different field types in the object, and adds a corresponding statement in front of the type definition character string when a type name and a name space are required to be specified. Finally, the generated type definition string write file is saved as a ts file. The device realizes automatic generation of the TypeScript type statement, writes the generated type definition character string into the file and saves the file as the ts file, supports direct import project use, reduces the error probability in the process of writing the type statement, and improves the development efficiency of developers.
The invention also discloses a readable storage medium, which includes Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art. The readable storage medium stores therein a generator of a TypeScript type declaration, which when executed by a processor, implements the steps of:
1. creating a json format file according to development requirements, and defining data in the json format file to generate a json data file.
2. And analyzing the json data file to generate a json object.
3. And generating a corresponding TypeScript type definition character string according to different field types in the json object.
4. And writing the generated TypeScript type definition character string into a preset file, and storing the TypeScript type definition character string into a file in a ts format.
In summary, the method and the system can quickly convert the needed json format file into the ts type file, improve the development efficiency of developers, and can lead out the corresponding file to support direct use in the project.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different point from other embodiments, so that the same or similar parts between the embodiments are referred to each other. For the method disclosed in the embodiment, since it corresponds to the system disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative elements and steps are described above generally in terms of functionality in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the several embodiments provided by the present invention, it should be understood that the disclosed systems, and methods may be implemented in other ways. For example, the system embodiments described above are merely illustrative, e.g., the division of the elements is merely a logical functional division, and there may be additional divisions when actually implemented, e.g., multiple elements or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some interface, system or unit indirect coupling or communication connection, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional module in the embodiments of the present invention may be integrated in one processing unit, or each module may exist alone physically, or two or more modules may be integrated in one unit.
Similarly, each processing unit in the embodiments of the present invention may be integrated in one functional module, or each processing unit may exist physically, or two or more processing units may be integrated in one functional module.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. The software modules may be disposed in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The method, the system and the device for generating the TypeScript type statement provided by the invention and the readable storage medium are described in detail. The principles and embodiments of the present invention have been described herein with reference to specific examples, the description of which is intended only to facilitate an understanding of the method of the present invention and its core ideas. It should be noted that it will be apparent to those skilled in the art that various modifications and adaptations of the invention can be made without departing from the principles of the invention and these modifications and adaptations are intended to be within the scope of the invention as defined in the following claims.

Claims (10)

1. A method for generating a TypeScript type declaration, comprising:
creating a json format file according to development requirements, and defining data in the json format file to generate a json data file;
analyzing the json data file to generate a json object;
generating a corresponding TypeScript type definition character string according to different field types in the json object;
and writing the generated TypeScript type definition character string into a preset file, and storing the TypeScript type definition character string into a file in a ts format.
2. The method for generating TypeScript type declaration according to claim 1, wherein the json format file includes character string type data, numeric type data, object type data, and data type data.
3. The method for generating a TypeScript type declaration according to claim 2, wherein the parsing the json data file to generate the json object includes:
invoking an fs file processing module under nodejs;
and reading and analyzing the content of the json data file by using a fs.readfile () method to generate a corresponding json object.
4. A method for generating a TypeScript type declaration according to claim 3, wherein said generating a corresponding TypeScript type definition string according to different field types in json objects includes: when the field value in the json object is a character string, generating and returning a character string type string;
when the field value in the json object is a numerical value, a numerical value type number is generated and returned.
5. The method for generating a TypeScript type declaration according to claim 4, wherein the generating a corresponding TypeScript type definition string according to different field types in json objects further comprises:
identifying each field in the json object by way of recursive processing when the field value in the json object is the object, until the identified field value is a string or a numeric value;
when the field value in the json object is an array, identifying element content in the array;
if the element content is a character string, generating and returning a character string array type string [ ]; if the element content is a numerical value, generating and returning a numerical value array type number [ ]; if the element content is the object element, identifying each field in the object element in a recursion processing mode, ending until the identified field value is a character string or a numerical value, and generating and returning object type data after the processing is completed.
6. The method for generating a TypeScript type declaration according to claim 5, wherein the generating a corresponding TypeScript type definition string according to different field types in json objects further comprises:
if the field type name and namespace in the json object have been specified, then a corresponding declaration is added in front of the generated TypeScript type definition string.
7. The method for generating a TypeScript type declaration according to claim 1, wherein writing the generated TypeScript type definition string into a preset file and saving the TypeScript type definition string as a file in a ts format, includes:
writing the generated TypeScript type definition character string into a preset file by using a writeFile () method of the fs file processing module;
the file path of the output file is specified and saved as a file in ts format.
8. A TypeScript type declaration generation system, comprising:
the file definition unit is configured to create a json format file according to development requirements and define data in the json format file so as to generate a json data file;
the file analysis unit is configured to analyze the json data file and generate a json object;
the type definition character string generation unit is configured to generate a corresponding TypeScript type definition character string according to different field types in the json object;
and the storage unit is configured to write the generated TypeScript type definition character string into a preset file and store the TypeScript type definition character string as a file in a ts format.
9. A TypeScript type declaration generation apparatus, comprising:
a memory for storing a generator of a TypeScript type declaration;
a processor, configured to implement the steps of the TypeScript type declaration generation method according to any one of claims 1 to 7 when executing the TypeScript type declaration generation program.
10. A readable storage medium, characterized by: the readable storage medium stores thereon a generation program of a TypeScript type declaration, which when executed by a processor, implements the steps of the generation method of TypeScript type declaration according to any one of claims 1 to 7.
CN202310786658.9A 2023-06-29 2023-06-29 Method, system, device and medium for generating TypeScript type statement Pending CN117406969A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310786658.9A CN117406969A (en) 2023-06-29 2023-06-29 Method, system, device and medium for generating TypeScript type statement

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310786658.9A CN117406969A (en) 2023-06-29 2023-06-29 Method, system, device and medium for generating TypeScript type statement

Publications (1)

Publication Number Publication Date
CN117406969A true CN117406969A (en) 2024-01-16

Family

ID=89485987

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310786658.9A Pending CN117406969A (en) 2023-06-29 2023-06-29 Method, system, device and medium for generating TypeScript type statement

Country Status (1)

Country Link
CN (1) CN117406969A (en)

Similar Documents

Publication Publication Date Title
CN111708539B (en) Application program code conversion method and device, electronic equipment and storage medium
US7610545B2 (en) Annotations for tracking provenance
US9483240B1 (en) Data binding dependency analysis
CN112114807A (en) Interface display method, device, equipment and storage medium
US20140282379A1 (en) Computer-implemented method, system and computer program product for displaying a user interface component
CN109739494B (en) Tree-LSTM-based API (application program interface) use code generation type recommendation method
CN108595171B (en) Object model generation method, device, equipment and storage medium
US20200210158A1 (en) Automated or machine-enhanced source code debugging
CN114153459A (en) Interface document generation method and device
CN110647360B (en) Method, device and equipment for processing device execution code of coprocessor and computer readable storage medium
US11275625B2 (en) System and method for automated application programming interface generation
CN116360735A (en) Form generation method, device, equipment and medium
KR20140116438A (en) Graphical representation of an order of operations
Savic et al. Use case specification at different levels of abstraction
CN117406969A (en) Method, system, device and medium for generating TypeScript type statement
CN116088864A (en) Assembling method, disassembling method, apparatus and storage medium
CN115629763A (en) Target code generation method and NPU instruction display method and device
CN114625372A (en) Automatic component compiling method and device, computer equipment and storage medium
KR20230040516A (en) Automation system and method for extracting intermediate representation based semantics of javascript
CN112306493A (en) Hot repair patch generation method and device, storage medium and computer equipment
CN110737431A (en) Software development method, development platform, terminal device and storage medium
CN117193781B (en) SIMSCRIPT language-oriented abstract syntax tree construction method and device
CN113971028B (en) Data processing method, apparatus, device, storage medium and computer program product
CN111736840B (en) Method for compiling applet application, method for running applet application, storage medium and electronic device
CN117806607A (en) PLC program compiling method and device based on array mapping memory address

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination