Comments (9)
I'm amazed that people figured out what this issue meant. My brain was imploding trying to understand what could possibly have been the bug: "Why would the () =>
part matter here? Why is the desired behavior just 'an error' without mentioning, like, what kind of error? Why wouldn't you be allowed to narrow from boolean
to true
in a type assertion? Wait, has 3 cut in front of 1 and 2 in the number line again? Am I... am I dreaming? This is a dream, isn't it?"
from typescript.
3 is always cutting in front of 1 and 2, he thinks he's so important having his visage plastered everywhere. Still better than that jerk 7. 6 still needs therapy to this day after witnessing t h e i n c i d e n t
from typescript.
This is working as intended. Using a type assertion you tell the compiler "shh.. trust me, it's this type, I know what I'm doing..."
@KDwevedi They surely mean the 1 > 3
case.
from typescript.
Maybe I'm just slow today, but why should this trigger an error?
from typescript.
...I was expecting the above code to be an error, since the 1 < 3 is always false.
Why is 1 < 3
false? <
is just the less than comparison operator, correct?
from typescript.
@dragomirtitian This is just a guess but maybe OP expects an error because 2 < 3
is always false? But then false as true
isnβt an error either soβ¦
from typescript.
I should have been more clear.
as @fatcerberus mentioned, I was expecting the above code to be an error, since the 1 < 3
is always false.
from typescript.
Note that all of these are valid...
const a = false as true;
const b = 'x' as 'y';
const c = 1 as 2;
from typescript.
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
from typescript.
Related Issues (20)
- Boolean narrowed to true only when generic type is explicitly provided while it shouldn't HOT 9
- Can't understand error -> Operator '+' cannot be applied to types 'BigInt' and 'BigInt' HOT 4
- Refactor type definitions and improve interface organization in types.ts HOT 1
- [question] Is there any library for linking the imported files?
- Uncaught Type assertion between Interface and Class Types can lead to runtime errors HOT 2
- Type unions are previewed out of order HOT 2
- Cannot Move React Class Component To New File HOT 2
- Template types don't resolve in conditional types HOT 7
- [NewErrors] 5.7.0-dev.20240825 vs 5.5.4 HOT 73
- [ServerErrors][JavaScript] 5.7.0-dev.20240825 vs 5.5.4 HOT 8
- [ServerErrors][TypeScript] 5.7.0-dev.20240825 vs 5.5.4 HOT 17
- Inconsistent boolean literal types in objects
- 5.6.1-rc Incorrectly assumes "this" is not nullish even when declared as such
- Allow module resolution Bundler with module NodeNext HOT 10
- Star export from type expression
- 5.6 regression: Array.prototype.reduce type inference regression HOT 8
- 5.6 regression: Inference related regression: Wider covariant inference gets picked over more narrow contravariant one HOT 12
- 5.6 regression: Inference with mixed in type intersection no longer compiles HOT 4
- 5.6 regression: Function inference with multiple T newly chooses less specific type HOT 2
- Isolated declarations quick fix results in redundant type arguments when the RHS is a new expression with explicit type arguments HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.