Weaken type checks based on CFA with assertion conditions
See original GitHub issueToo strict for tests.
cc @ahejlsberg
TypeScript Version: 3.7.x-dev.20191207
Search Terms:
Code
declare function assert(value: any): asserts value;
declare const set: Set<0>;
assert(set.size === 0);
set.add(0);
assert(set.size === 1);
Expected behavior: pass Actual behavior: This condition will always return ‘false’ since the types ‘0’ and ‘1’ have no overlap.(2367) Playground Link: http://www.typescriptlang.org/play/index.html?ssl=1&ssc=1&pln=6&pc=24#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXygGdCQYMAKANygmRAC4DUBPASkaJLMPmtpADcAKFCRYCMHkIZ4JDIwDKIDAB4ADAD5hQzqQpyAdISwAvBAF5L8Na2GGowYORvDdZcoeNn4l8-ACMtkA
Related Issues:
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
cfa-candidate-cbt-checklist-2020.pdf
Scheduled exam appointment. Reviewed all testing policies. Confirmed valid international travel passport—the only type of identification accepted.
Read more >Reasoning about parameterized components with dynamic ...
In this approach, when checks are excluded the underlying code is just as efficient as if assertions were “compiled out.” In addition, a...
Read more >FOREIGN TRADE BARRIERS - USTR
The merchandise trade data contained in the NTE are based on total ... These are among the most difficult types of foreign practices...
Read more >Final rule: Good Faith Determinations of Fair Value - SEC.gov
The rule will provide requirements for determining fair value in good ... types of valuation risk.39 As discussed below, we are reiterating ...
Read more >vtable.md in doc/proposals – Cforall
type once as a parameter. Extensions may later loosen these requirements. 49. 50, Also note this applies to the final expanded list of...
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
Let’s imagine that we disable overlap detection. Then what do you expect
set.size
to be at the end of your example code? I think it would end up looking like this:Unless you want to narrow to
never
, I suspect you are usingasserts
functions in places you shouldn’t. Perhaps you want twoassert()
functions, one which performs CFA narrowing and one which doesn’t:Or, is there some explicit suggestion here for how to modify the behavior of TS assertion functions so that they behave well for your use case without disabling CFA narrowing entirely?
@ahejlsberg Can you make your new assertion functions usable for the existing tests? They don’t support some typical test patterns. Otherwise I have to revert the introduction of them.