Currently running typescript-json-schema with an undefined root type

Trying to execute the command

typescript-json-schema --noExtraProps --required --refs false -o ./types.schema.json ./tsconfig.json *
using the typescript-json-schema npm package results in an error:

Error: Not supported: root type undefined
    at JsonSchemaGenerator.getDefinitionForRootType (\node_modules\typescript-json-schema\dist\typescript-json-schema.js:473:27)
    at JsonSchemaGenerator.getTypeDefinition (\node_modules\typescript-json-schema\dist\typescript-json-schema.js:1127:26)
    at JsonSchemaGenerator.getDefinitionForRootType (\node_modules\typescript-json-schema\dist\typescript-json-schema.js:560:53)
    at JsonSchemaGenerator.getTypeDefinition (\node_modules\typescript-json-schema\dist\typescript-json-schema.js:1127:26)
    at JsonSchemaGenerator.getUnionDefinition (\node_modules\typescript-json-schema\dist\typescript-json-schema.js:721:32)
    at JsonSchemaGenerator.getTypeDefinition (\node_modules\typescript-json-schema\dist\typescript-json-schema.js:1098:26)
    at JsonSchemaGenerator.getDefinitionForProperty (\node_modules\typescript-json-schema\dist\typescript-json-schema.js:594:31)
    at\node_modules\typescript-json-schema\dist\typescript-json-schema.js:908:37
    at Array.reduce (<anonymous>)
    at JsonSchemaGenerator.getClassDefinition (\node_modules\typescript-json-schema\dist\typescript-json-schema.js:906:45)

Answer №1

The reason for this error is due to the fact that type utilities for schemas only support optional properties, not unions with undefined. An example of code that will trigger this error is:

interface car {
 model:string | undefined;
}

To resolve this issue, your types should be defined as follows:

interface car {
 model?:string;
}

If you encounter a similar problem, there is an ongoing discussion on Github regarding this issue in ajv here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Incompatibility issues between NestJS and socket.io package

After diligently following the documentation, I attempted to install and work with socket.io on nestjs. However, I encountered multiple issues when installing packages. Despite trying different methods to update the package, nothing seemed to resolve the i ...

Warning in TypeScript: TS7017 - The index signature of the object type is implictly assigned as type "any"

An alert for TypeScript warning is popping up with the message - Index signature of object type implicitly has any type The warning is triggered by the following code block: Object.keys(events).forEach(function (k: string) { const ev: ISumanEvent ...

The functionality of the Angular click event binding seems to be malfunctioning

When I click on a radio button, I want to see relevant selections. Below are the files: app.component.html <div class="col-md-3"> <b>Select Category</b><br> <input type="radio" name="colors" [(ngModel)]="typing" (clic ...

What is the correct method for typing a React functional component with properties?

Here's a react functional component I have created... const MyFunction = () => { // lots of logic MyFunction.loaded = someBoolean; return <div>just one line</div> } MyFunction.refresh = () => ....... I added two properti ...

The Angular 2 view appears on the screen before the data finishes loading in the ngOnInit

Utilizing the github API in my angular 2 application, I encounter an issue where the view renders before ngOnInit has finished loading data. This leads to a Cannot read property of undefined error. The relevant portion of my code is as follows: ngOnInit() ...

Guide on incorporating text input areas into specific positions within a string

Looking for a way to replace specific words in a string with input fields to enter actual values? For example... Dear Mr. [Father_name], your son/daughter [name] did not attend class today. This is what I want it to look like... Dear Mr. Shankar, your ...

I am having trouble locating my source code within the Typescript module

My issue lies with a file called Server.js, which holds the code for export class Program and includes <reference path='mscorlib.ts'/>. However, when I compile it using the command: tsc -t ES5 Server.ts --module commonjs --out Server.js T ...

A more efficient method for refreshing Discord Message Embeds using a MessageComponentInteraction collector to streamline updates

Currently, I am working on developing a horse race command for my discord bot using TypeScript. The code is functioning properly; however, there is an issue with updating an embed that displays the race and the participants. To ensure the update works co ...

Conceal mat-table column when form field is empty

As a newcomer to the world of programming, I am currently tackling a table that includes form fields for filtering purposes. My goal is to dynamically hide or show table columns based on whether a form field has a value or not. In my table.component.ts ...

What is the best way to find a partial string match within an array of objects when using Jest?

I am currently utilizing the following versions: Node.js: 9.8.0 Jest: 22.4.2 A function called myFunction is returning an array structured like this: [ ... { id: 00000000, path: "www.someUrl.com/some/path/to" } ... ] I ...

How to specify the file path for importing a custom module?

I am currently learning Angular 2 and encountering an issue with importing a custom module that contains interface declarations. Here is my folder structure: https://i.stack.imgur.com/heIvn.png The goal is to import product.interface.ts into a component ...

Asserting a type null to undefined

Can anyone explain why TypeScript doesn't flag an error in this scenario, where null is assigned to a property expecting number or undefined? typescriptlang example type T1 = { value: number | null } type T2 = { value?: number }; const v1: T ...

TypeScript excels in typechecking when using two individual assignments, but may encounter issues when attempting typechecking with tuple

I am quite puzzled by a discovery I made and I am seeking to understand why TypeScript is displaying this behavior and what the underlying reason may be. Here is the code snippet: class A { constructor(public name : String, public x = 0, public y = 0) ...

Every instance of 'WeakMap' must include the same type parameters

While developing an Ionic App, I encountered a strange issue. Everything was running smoothly until I cloned the source code to a different machine, which resulted in an error that is displayed in the attached image. Even though there are no compilation e ...

Guide on creating an interface for a JSON object with an array of custom functions

I am working on developing an interface for a JSON object that consists of n keys with unknown names, each containing an array of functions with specific signatures. // CLASSES class Server { // Private variables mapping : IMapping = {} // ...

The items in my array have been replaced with new objects

I am facing an issue with storing objects in an array within a function. Every time the function is called, a new object is received and I want to add it to the existing array without overwriting the previous objects. This way, all the objects can be acc ...

Leveraging AngularJS services within an Angular service

I am currently in the process of transitioning my AngularJS application to Angular. To facilitate this transition, I plan to create a hybrid application that combines both frameworks until the conversion is complete. However, I have encountered an issue wi ...

Overriding a library function with the same namespace name in a mocking scenario

In a scenario akin to a previous inquiry, my goal is to mock an external library utilizing sinon. The challenge lies in the fact that this library exports two functions and a namespace under the identical name of FastGlob. While I possess a basic understa ...

Models reference each other incorrectly, causing a problem of circular dependencies

file-admin.ts import mongoose, { Schema, Document } from 'mongoose'; import UserRole, { IUserRole } from './user-role.model'; export interface IFileAdmin extends Document { role: IUserRole; } let fileAdminSchema = new Schema<IF ...

Creating a custom data type for the Tanstack table filtering function

I developed a unique filter function specifically for enhancing the functionality of Tanstack Table by utilizing fuse.js. Despite my efforts, TypeScript consistently raises concerns when I try to define the type for my custom function. My goal is to alig ...