question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to force a field to be a specific type?

See original GitHub issue

I am trying to do something like:

/**
* How to force a Widget to be encoded as number?
*
* @type number
*/
export interface Widget {}

export interface House {
    name: string;

    mainWidget: Widget;
    otherWidgets: Widget[];
}

So that the mainWidget field is encoded as a regular “number”, and also otherWidgets will be an array of numbers.

In other words I would like to get the following schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "properties": {
        "name": {
            "type": "string"
        },
        "mainWidget": {
            "type": "number"
        },
        "otherWidgets": {
            "items": {
                "type": "number"
            },
            "type": "array"
        }
    },
    "required": [
        "name",
        "mainWidget",
        "otherWidgets"
    ],
    "type": "object"
}

thank you

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
domoritzcommented, Jan 28, 2017

The issue is that we try to infer types and defintions and overriding properties can have weird effects. I added some code so it works for types but I’m not convinced that it’s a good idea in general to let users override properties.

0reactions
benny-medflytcommented, Jan 30, 2017

I’m not familiar with typescript-json-schema source code, but maybe in a few days I’ll have time to try to figure this out

Read more comments on GitHub >

github_iconTop Results From Across the Web

Force a field to be an object type - Stack Overflow
I'm using datatypes to filter numeric vs categorical - all fields are numeric. I'll be dropping and adding columns pretty often so a...
Read more >
Solved: Forcing a field type - Designer - Alteryx Community
Solved: Hi, Is it possible to force a field type for a particular column in an excel input file? I have a use...
Read more >
Forcing specific formatting in an input field
Solved: I have an input field that needs to take a costing string, depending on an earlier quesion the format will either be...
Read more >
How to force Input field to enter numbers only using JavaScript
Now forcing input field type=”text” to accept numeric values only by using Javascript or jQuery. You can also set type=”tel” attribute in the ......
Read more >
Change the Custom Field Type - Salesforce Help
From the management settings for the field's object go to Fields.For fields on Salesforce Knowledge article types from Setup enter Knowledge Article Types...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found