Skip to content

Incorrect type for a const with an empty string value #393

Closed
@johnbillion

Description

@johnbillion

Since #290 the const keyword is supported and acts as an alias for an enum with one value. This is great but it does not work correctly for a const that contains an empty string. Example:

Input:

"foo": {
	"const": ""
}

Expected output:

foo: ""

Actual output:

foo: {
	[k: string]: unknown;
};

An enum containing a single value of an empty string does work as expected:

"foo": {
	"enum": [
		""
	]
}

What use is a const with an empty string?

I use these for fields where the value is required and always a string but can be empty, for example an optional URL. Of course it should be nullable/optional really but this is a legacy application.

"url": {
	"oneOf": [
		{
			"type": "string",
			"format": "uri"
		},
		{
			"enum": [
				""
			]
		}
	]
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions