Converting JSONSchema into TypeScript: Creating a structure with key-value pairs of strings

I am working with json-schema-to-typescript and looking to define an array of strings.

Currently, my code looks like this:

      "type": "object",
      "description": "...",
      "additionalProperties": true,
      "items": {
        "type": "string"
      }

However, when converted to TS, it outputs [k: string]: unknown;

Is there a way for it to generate [k: string]: string; instead?

Appreciate your help in advance

Answer №1

items is typically used with arrays, however in this case it seems you have defined it as

"type": "object"
. Have you considered adjusting the type to
"type": "array"
and removing the additionalProperties?

Answer №2

The solution was to eliminate the items attribute and switch it to

"additionalProperties": { "type": "string" }

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

The transfer of JSON data to PHP through AJAX is not successful

I have encountered an issue while attempting to send a JSON string to a PHP file using ajax. The problem lies in the variable I am posting not being delivered when employing the JQUERY ajax method as illustrated below: <DOCTYPE html> <html> ...

Exploring the versatility of orderBy and filter in handling cross-referenced content across multiple JSON objects

Is there a way to filter and search for the item name when the item details are sourced from another JSON object? Demo: http://codepen.io/anon/pen/GjAxKX While the rest of the filtering and ordering functionalities are functioning correctly, I am struggl ...

The export from chart.js does not include a member named 'ChartDataSets'. Perhaps you were referring to 'ChartDataset'? ts(2724)

Encountered an error message when trying to import ChartDataSets in line-chart.component.ts 'chart.js' does not have a member named 'ChartDataSets'. Perhaps you meant 'ChartDataset'? Uncertain about the source of the issue. C ...

What could be the issue with this JSON data?

After referencing this stackoverflow thread on how to return success/error messages for JQuery .ajax() using PHP, I implemented the accepted answer in my PHP script. I am returning the following json with correct headers: Content-type: application/json and ...

Highcharts still unable to display series data despite successful decoding efforts

After receiving JSON decoded data from the server and using $.parseJSON to decode it, I am assigning it to the series in Highcharts. Although there are no console errors, the chart refuses to display. Below is the code snippet: <!DOCTYPE html> < ...

Gson transforms objects into JSON structures similar to Firebase

In the past, I manually created a list of data that was stored locally in a database. Now, I want to parse this data and import it into Firebase databases using the import json option. However, the JSON format I get doesn't match the one generated by ...

What could be the reason for the Angular dropdown values not appearing?

Encountering an issue with binding data to a dropdown element, as the dropdown displays NOTHING SELECTED. <select #classProductTypeCombobox name="classProductTypeCombobox" class="form-control col-md-3" [(ngModel)]="classifica ...

Invoke a general function with corresponding generic parameters

I am currently working on a function that takes another function and its arguments as parameters, then runs the function with the provided arguments and returns the result while maintaining the data types. If the function being provided has a fixed return ...

Import the complete JSON file into a variable as an array

I am struggling with loading an external json file (locations.json) into a variable and then using the information found here: http://www.json.org/js.html Despite trying various methods, I have not been successful in populating the variable. Even after fo ...

Retrieving the necessary key values from a JSON dictionary

I'm attempting to retrieve keys from a dictionary using JavaScript. The user uploads a .json file containing the dictionary, and I want to display the keys from that uploaded dictionary. It's important to note that only .json dictionaries can be ...

Eliminate apostrophes in a string by using regular expressions

Can someone help me with this word What is The Answer? I need to eliminate the space and apostrophe '. To remove spaces, should I use this method: data.text.replace(/ +/g, ""). But how can I remove the apostrophe? ...

Problem encountered when trying to load JSON data using ajax

I encountered the following issue : SyntaxError: missing ; before statement {"users":[{"name":"A Lindsay","active":true,"id":"","login":"alindsa This is how the JSON data appears: { "users": [{ "name": "A Lindsay", "active": tr ...

Leveraging property information for a dropdown field

In my index.tsx file, I am fetching data that I pass to the component FormOne. This allows me to access the data in FormOne using props.data const [data, setData] = useState([]); ... return ( ... <FormOne data={data} /> ); I am looking to ...

The absence of transpiled Typescript code "*.js" in imports

Here is an example of the code I am working with: User.ts ... import { UserFavoriteRoom } from "./UserFavoriteRoom.js"; import { Room } from "./Room.js"; import { Reservation } from "./Reservation.js"; import { Message } from ...

Using Ionic2, include NavController into Injectable Service

Having an issue with an Injectable Service in Angular2 with Ionic2 framework. Here is how my service is structured: import {Injectable} from '@angular/core'; import {NavController} from 'ionic-angular'; @Injectable() export class Vie ...

Leverage process.env variables within your next.config.js file

Currently, I have an application running on NextJS deployed on GCP. As I set up Continuous Deployment (CD) for the application, I realized that there are three different deploy configurations - referred to as cd-one.yaml, cd-two.yaml, and cd-three.yaml. Ea ...

A data type labeled as 'undefined' needs to include a method called '[Symbol.iterator]()' which will then return an iterator

I've been working on converting my reducer from JavaScript to TypeScript, but I keep encountering a strange error that I can't seem to resolve. The issue arises when I attempt to use ellipsis for array deconstruction in the reducer [...state.mess ...

Adjusting the settimeout delay time during its execution

Is there a way to adjust the setTimeout delay time while it is already running? I tried using debounceTime() as an alternative, but I would like to modify the existing delay time instead of creating a new one. In the code snippet provided, the delay is se ...

Getting JSON data from an array in Laravel is a simple task

I have a `foreach` loop that I need to use to return each object in an array in JSON format. Allow me to introduce my controller: $childCategory = ChildCategory::whereProductCategoryId($catId)->get(); $data = array(); foreach ($childCategory as $child ...

Next.js is refusing to render an array of HTML elements

Consider this scenario where I have a block of code in TypeScript that attempts to create and display a list of elements. Here is a sample implementation: const MenuList = ():ReactElement => { const router = useRouter(), liElements:any = []; con ...