typescript_parser.py

View code on Github

Module for parsing TypeScript interfaces and types.

class ts_backend_check.parsers.typescript_parser.TypeScriptInterface(name: str, properties: List[str], optional_properties: List[str], parents: List[str])[source]

Represents a TypeScript interface with its properties and parent interfaces.

class ts_backend_check.parsers.typescript_parser.TypeScriptParser(concatenated_types_file: str)[source]

Parser for TypeScript interface files.

Parameters:
concatenated_types_filestr

The file path for the TypeScript file to parse.

parse_interfaces() Dict[str, TypeScriptInterface][source]

Parse TypeScript interfaces from the file.

Returns:
Dict[str, TypeScriptInterface]

The interface parsed into a dictionary for future processing.

get_ignored_fields() Set[str][source]

Extract fields marked as ignored in comments.

Returns:
Set[str]

The field names that are marked with a ts-backend-check ignore identifier.

static _extract_properties(interface_body: str) List[str][source]

Extract both real properties and ‘ignored’ comment backend fields from interface bodies.

Parameters:
interface_bodystr

A string representation of the interface body of the model.

Returns:
List[str]

The property names from the model interface body.

static _extract_optional_properties(interface_body: str) List[str][source]

Extract all optional properties from interface bodies.

Parameters:
interface_bodystr

A string representation of the interface body of the model.

Returns:
List[str]

The optional property names from the model interface body.