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.

Question: Why does some properties allow strings while other doesn't?

See original GitHub issue

Hi @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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
freniccommented, Mar 8, 2020

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.

1reaction
meyercommented, Mar 2, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

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