UNPKG

@rxap/json-schema-to-typescript

Version:

Generate TypeScript interfaces from JSON Schema definitions. It allows you to programmatically create and manipulate TypeScript interface definitions based on JSON schema inputs. The package provides utilities to convert JSON schema to TypeScript interfac

22 lines (21 loc) 1.81 kB
import { ImportDeclarationStructure, OptionalKind, SourceFile } from 'ts-morph'; /** * This function, `CoerceImports`, is used to coerce import declarations in a given source file. It takes two parameters: `sourceFile` and `structures`. * * @param {SourceFile} sourceFile - The source file in which the import declarations are to be processed. This is an instance of the `SourceFile` class. * * @param {Array<OptionalKind<ImportDeclarationStructure>> | OptionalKind<ImportDeclarationStructure>} structures - An array of import declaration structures or a single import declaration structure. Each structure can be of type `OptionalKind<ImportDeclarationStructure>`, which means it may or may not contain certain properties. * * The function iterates over each import declaration structure in `structures`. For each structure, it extracts the following properties: `moduleSpecifier`, `namedImports`, `namespaceImport`, `isTypeOnly`, and `defaultImport`. * * If `namedImports` is present, it checks if the named imports are supported using the `isSupportedNamedImports` function. If not, it throws an error. If they are supported, it coerces the named imports using the `coerceNamedImports` function. * * If `namespaceImport` is present, it coerces the namespace import using the `coerceNamespaceImport` function. * * If `defaultImport` is present, it coerces the default import using the `coerceDefaultImport` function. * * The function does not return any value. * * Note: This function does not modify the original `sourceFile` or `structures` parameters. It only processes and validates the import declarations. */ export declare function CoerceImports(sourceFile: SourceFile, structures: Array<OptionalKind<ImportDeclarationStructure>> | OptionalKind<ImportDeclarationStructure>): void;