Question: Why does some properties allow strings while other doesn't?
See original GitHub issueHi @frenic, I have a question! 😀
Most properties seem to allow string values even if they have a finite number of valid values, for instance:
type AlignItemsProperty = Globals | SelfPosition | "baseline" | "normal" | "stretch" | string;
type FlexFlowProperty = Globals | "column" | "column-reverse" | "nowrap" | "row" | "row-reverse" | "wrap" | "wrap-reverse" | string;
But other doesn’t:
type FlexDirectionProperty = Globals | "column" | "column-reverse" | "row" | "row-reverse";
type FlexWrapProperty = Globals | "nowrap" | "wrap" | "wrap-reverse";
I ran into these kinds of problems while using the properties that don’t allow any string.
Is this intentional? 🤔
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why can't I add properties to a string object in javascript?
@Mike When properties are accessed (or then methods are invoked) on primitive String values, the JavaScript engine wraps the value in a String...
Read more >Interface with optional properties incorrectly allows setting other ...
When the name isn't statically determinable, we error on the lenient side and assume you're using some construction that will resolve to a...
Read more >Object.defineProperty() - JavaScript - MDN Web Docs
A function which serves as a setter for the property, or undefined if there is no setter. When the property is assigned, this...
Read more >Objects - The Modern JavaScript Tutorial
In short, there are no limitations on property names. They can be any strings or symbols (a special type for identifiers, to be...
Read more >How the Question Mark (?) Operator Works in JavaScript
The ? operator is used in conditional statements, and when paired ... say you have code that calls on an object property that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We should close this. I don’t believe there’s much more we can do to improve type checking at this moment. We also have to keep in mind that false positive type errors are more annoying than false positive warnings in e.g. a linting tool. CSSType should only provide basic type checking and let the responsible to the developer and other tools where values becomes more complicated.
if you search closed issues for
string
you’ll see this question gets asked fairly frequently (it’s probably worth a README FAQ). There’s an explanation here: https://github.com/frenic/csstype/issues/8#issuecomment-364845647