Title: CFA Assertions Not Active on Implicitly-Typed Function Calls · Issue #33580 · microsoft/TypeScript · GitHub
Open Graph Title: CFA Assertions Not Active on Implicitly-Typed Function Calls · Issue #33580 · microsoft/TypeScript
X Title: CFA Assertions Not Active on Implicitly-Typed Function Calls · Issue #33580 · microsoft/TypeScript
Description: TypeScript Version: 3.7.0-insiders.20190923 (this tgz from this comment) Search Terms: asserts cfa control flow analysis Code class Foo { } interface BarChild { parent: Bar; } class Bar { static staticAdd(f: Foo): asserts f is Foo & BarC...
Open Graph Description: TypeScript Version: 3.7.0-insiders.20190923 (this tgz from this comment) Search Terms: asserts cfa control flow analysis Code class Foo { } interface BarChild { parent: Bar; } class Bar { static st...
X Description: TypeScript Version: 3.7.0-insiders.20190923 (this tgz from this comment) Search Terms: asserts cfa control flow analysis Code class Foo { } interface BarChild { parent: Bar; } class Bar { static st...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/33580
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"CFA Assertions Not Active on Implicitly-Typed Function Calls","articleBody":"**TypeScript Version:** 3.7.0-insiders.20190923 (this [tgz](https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/45201/artifacts?artifactName=tgz&fileId=FCC96CD1470D020E21159D18DAC814941830D31C28D43629A094AF099B11388B02&fileName=/typescript-3.7.0-insiders.20190923.tgz) from [this comment](https://github.com/microsoft/TypeScript/pull/32695#issuecomment-534269544))\r\n\r\n**Search Terms:** `asserts` `cfa` `control flow analysis`\r\n\r\n**Code**\r\n\r\n```ts\r\nclass Foo {\r\n}\r\n\r\ninterface BarChild {\r\n parent: Bar;\r\n}\r\n\r\nclass Bar {\r\n static staticAdd(f: Foo): asserts f is Foo & BarChild {}\r\n add(f: Foo): asserts f is Foo & BarChild {}\r\n innerTest() {\r\n const innerFoo = new Foo();\r\n this.add(innerFoo);\r\n innerFoo.parent; // this compiles successfully\r\n }\r\n}\r\n\r\nfunction main() {\r\n const foo1 = new Foo();\r\n const bar1 = new Bar();\r\n bar1.add(foo1);\r\n foo1.parent; // this is an ERROR - Property 'parent' does not exist on type 'Foo'. ts(2339)\r\n\r\n const foo2 = new Foo();\r\n Bar.staticAdd(foo2);\r\n foo2.parent; // this compiles successfully\r\n}\r\n```\r\n\r\nThe `Bar.add` assertion works when called inside another method of `Bar` but fails when called externally from `main`. I added a static function assertion to show that assertion still works otherwise in `main`.\r\n\r\n**Expected behavior:** In `main` after `bar1.add(foo1)`, `foo1` should be of type `Foo & BarChild`.\r\n\r\n**Actual behavior:** In `main` after `bar1.add(foo1)`, `foo1` is still type `Foo`.\r\n\r\n**Playground Link:** I've duplicated the sample code above in [this](https://www.typescriptlang.org/play/?ts=Nightly#code/MYGwhgzhAEBiD29oG8BQBfVqCWA7ALgKYBOAZmMIdAEJjEDCAFtiACYqrRfQAOdhBAFw06AbgxZQkGLWIdu0CPjD5swRctXAAgq1YAKUsITwAlMOkl8MUtGwwT0AGQiGzNikwKwew8cTm0JbE1tC29nCIzq5MLOzIXtx4uCQAKoRK+qbyCtzA8LhKdrgpxI4AvNApAO6R8Fniudz4zBAAdD4GySQmpo1NxaUmbXzEAviiXAD0U9AtEfkAtjwsGYoArsCUUKTrICAAnpzcmJiou7jAqgXQi2B4WTlc+YX4YYgAjNCVNXUNx88CkUAEZ0L4-Qi1WT-BSg4gfDq+UifPoA97wBGjcaTaAzOatOwwMC4aAAUQASuSAPLk6AAWmgAAViPAeFYDtAAORYgic6CseBrXDwN6EAAe9jeN3wBzZXJMnLacwg+gATABmdUATlMWAULyKyPgqu+VUhf1RClkbSUKjUugMRtVlu4TpG-AIOLx8xgSxWIDWEE22wgu32R3QQA) playground link, but at the time of posting the nightly version does not have these changes.\r\n\r\n**Related Issues:** https://github.com/microsoft/TypeScript/pull/32695 This feature was merged to master yesterday, so instead of commenting on a closed PR I opened a new issue. ","author":{"url":"https://github.com/molisani","@type":"Person","name":"molisani"},"datePublished":"2019-09-24T15:04:33Z","url":"https://github.com/microsoft/TypeScript/issues/33580"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:04537708-a3d5-c7c0-1294-e39a34252891 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E5A:A99C2:E022F2:120651A:6B00F534 |
| html-safe-nonce | 421d7550c9ae04cf78fa856895c8374e43b90be446fa056f732a8e8b31b04d00 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTVBOkE5OUMyOkUwMjJGMjoxMjA2NTFBOjZCMDBGNTM0IiwidmlzaXRvcl9pZCI6IjgyOTgxNzk4NjE5Njk2OTYwNTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b5f55d61b24916348ae6c131808cd67aa73538caa0d56413caf949c937e5d3da |
| hovercard-subject-tag | issue:497748670 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/33580/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bbaad315b75fcf6447ca72f96efd6cb6d27b6eb4041b9c394322979058ea704e/microsoft/TypeScript/issues/33580 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bbaad315b75fcf6447ca72f96efd6cb6d27b6eb4041b9c394322979058ea704e/microsoft/TypeScript/issues/33580 |
| og:image:alt | TypeScript Version: 3.7.0-insiders.20190923 (this tgz from this comment) Search Terms: asserts cfa control flow analysis Code class Foo { } interface BarChild { parent: Bar; } class Bar { static st... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | molisani |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width