If the when clause only contains one condition, then you can just invert that single condition with the !
operator. For the current list of operators in when-clauses, see the official docs: https://code.visualstudio.com/api/references/when-clause-contexts#conditional-operators.
If the when clause contains multiple condition joined by logical operators...
See this GitHub issue: Add support for parenthesis in "when" conditions #91473, which was added to VS Code's March 2023 Milestone, and was closed as completed by the context keys: implement a new parser (and a scanner/lexer) for 'when' clauses #174471 pull request. You can read about the exact syntax and grammar there. Here's a quote of its syntax and grammar in Extended Backus-Naur form:
expression ::= or
or ::= and { '||' and }*
and ::= term { '&&' term }*
term ::=
| '!' (KEY | 'true' | 'false')
| primary
primary ::=
| 'true'
| 'false'
| '(' expression ')'
| KEY '=~' REGEX
| KEY [ ('==' | '!=' | '<' | '<=' | '>' | '>=' | 'not' 'in' | 'in') value ]
value ::=
| 'true'
| 'false'
| 'in'
| KEY
| SINGLE_QUOTED_STR
| EMPTY_STR
See also the announcement / discussion issue ticket for the new feature: Upcoming when clause context parser
#175540.
Fun note: Even before parenthesis support in when clauses got added, you could usually use De Morgan's laws as a workaround to negate when-clauses.