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.

Allow guards to work with undefined variables

See original GitHub issue
.guard () when (@variable) {
  a {
    color: red;
  }
}

Variable isn’t defined, therefore no output.

@variable: true;

.guard () when (@variable) {
  a {
    color: red;
  }
}

Variable is definied, therefore output:

a {
  color: red;
}

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:46 (24 by maintainers)

github_iconTop GitHub Comments

4reactions
ashendencommented, Jan 3, 2016

Has there been any movement on this request? I’ve been anxious for an undefined variable check for some time now. At the moment, I have a work around that is far from ideal…

p {
  & when not (@body-text-color = null) {
    color: @body-text-color;
  }
}

but, for this to work, the variable must exist and be defined as null by default. This would be far more effective/flexible if I could just instead check if the variable even exists in the first place.

3reactions
matthew-deancommented, Jul 7, 2018

What’s also happened since this was open is the if() function. So you can do color: if((@variable), green, red);

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you implement a guard clause in JavaScript?
jQuery ensures that undefined really is undefined and not some variable by doing this: function(undefined) { ... })() . Inside that closure, ...
Read more >
How to check for undefined variables | Cruftless Craft
It reads as null which means you can guard against undefined errors like this: {# Check a variable with an empty default filter...
Read more >
How To Do Anything in TypeScript With Type Guards
Type guards allow for run-time type checking by using expressions to see if ... type guard to remove undefined from the type of...
Read more >
How to use type guards in TypeScript - LogRocket Blog
A type guard is a TypeScript technique used to get information about the type of a variable, usually within a conditional block.
Read more >
5 Methods to use Type Guards in TypeScript - Bits and Pieces
With the help of typeof keyword, TypeScript can identify the variables declared separately supporting the Types given below. String; Boolean; Number; Undefined ......
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