Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
johnbillion opened this issue Apr 29, 2021 · 1 comment · Fixed by #398
Closed

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

johnbillion opened this issue Apr 29, 2021 · 1 comment · Fixed by #398

Comments

@johnbillion
Copy link
Contributor

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": [
				""
			]
		}
	]
},
@bcherny
Copy link
Owner

bcherny commented Sep 12, 2021

Published 10.1.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants