Title: AngularJs TypeScript typings and --strictFunctionTypes · Issue #16617 · angular/angular.js · GitHub
Open Graph Title: AngularJs TypeScript typings and --strictFunctionTypes · Issue #16617 · angular/angular.js
X Title: AngularJs TypeScript typings and --strictFunctionTypes · Issue #16617 · angular/angular.js
Description: I'm submitting a ... bug report feature request design discussion TypeScript introduced a new strictness flag with TS 2.7 - https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#strict-function-types It makes typechecki...
Open Graph Description: I'm submitting a ... bug report feature request design discussion TypeScript introduced a new strictness flag with TS 2.7 - https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#s...
X Description: I'm submitting a ... bug report feature request design discussion TypeScript introduced a new strictness flag with TS 2.7 - https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScri...
Opengraph URL: https://github.com/angular/angular.js/issues/16617
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"AngularJs TypeScript typings and --strictFunctionTypes","articleBody":"**I'm submitting a ...**\r\n\u003c!-- (check one with \"x\") -->\r\n- [ ] bug report\r\n- [ ] feature request\r\n- [x] design discussion \u003c!--(Please do not submit support requests here - see above)-->\r\n\r\nTypeScript introduced a new strictness flag with TS 2.7 - https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#strict-function-types\r\n\r\nIt makes typechecking for callback based APIs much stricter. For example:\r\n\r\n```typescript\r\nfunction f(mixedArray: (string|number)[]) {\r\n mixedArray.map((x: string) => x.charAt(0));\r\n}\r\n```\r\nonly errors when --strictFunctionTypes is turned on.\r\n\r\nAngularJs has many callback based APIs, which will be checked at more strictly with the flag. Some real bugs will be exposed, but also it will start erring on many correct patterns. For example:\r\n\r\n```typescript\r\n{\r\n require: 'ngModel'\r\n link: (...., controller: NgModelController) {...}\r\n```\r\n\r\nThis is now an error because TS doesn't know that require and link are related. As written the typings require one handle the full spectrum of options in the link function `IController | IController[] | {[key: string]: IController}`.\r\n\r\nTS types are quite expressive and @gkalpak and I tried to write up some prototype of typings that are aware of the link between require and link:\r\n\r\n```typescript\r\ninterface IDirective\u003cT extends string|string[]> {\r\n link?: (x: LinkT\u003cT>) => void;\r\n require?: T;\r\n}\r\n\r\ntype LinkT\u003cT> =\r\n T extends string ? IController : T extends string[] ? IController[] : never;\r\n```\r\nBut even with full conditional types, it is impossible to extend this for user-defined directives.\r\n\r\nSo as plan B, I am going to contribute some nice type aliases to DefinitelyTyped ```type LinkFnControllerType = IController | IController[] | {[key: string]: IController}```\r\nand propose the canonical solution to be writing the link function as:\r\n\r\n```typescript\r\nlink: (..., controller: angular.LinkFnControllerType) => {\r\n let myController = controller as MyControllerType;\r\n}\r\n```\r\n\r\nOne added benefit is that there is an explicit 'as' cast to remind the reader to check with the 'require' and controller statements.\r\n","author":{"url":"https://github.com/rkirov","@type":"Person","name":"rkirov"},"datePublished":"2018-06-28T00:25:50Z","url":"https://github.com/angular/angular.js/issues/16617"}
| 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:c2225328-7f12-a5ae-4a82-5808c16bd17c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9340:2F888F:64066F:90713C:6AFD7AD2 |
| html-safe-nonce | d4adb8765c182e5179e4123184e2afc2498960a30a5bf431839bf75ef31a439e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MzQwOjJGODg4Rjo2NDA2NkY6OTA3MTNDOjZBRkQ3QUQyIiwidmlzaXRvcl9pZCI6IjM5MjE3NjI1NTcwNjAwMjA5NDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0a2739b12c49eceefe1179b5b001f8b3e5c3fe378d7db350347719cda1e1f2b6 |
| hovercard-subject-tag | issue:336432370 |
| 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/angular/angular.js/16617/issue_layout |
| twitter:image | https://opengraph.githubassets.com/18512e87f5d06087486dfda61c4a0b218d2f4bb483609f05863969becd34072c/angular/angular.js/issues/16617 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/18512e87f5d06087486dfda61c4a0b218d2f4bb483609f05863969becd34072c/angular/angular.js/issues/16617 |
| og:image:alt | I'm submitting a ... bug report feature request design discussion TypeScript introduced a new strictness flag with TS 2.7 - https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#s... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rkirov |
| hostname | github.com |
| expected-hostname | github.com |
| None | 544ff6b59bd215c4609120f6e334dbd0b00d34fb6f8bc03a476f72256998887e |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular.js git https://github.com/angular/angular.js.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 460078 |
| octolytics-dimension-repository_nwo | angular/angular.js |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 460078 |
| octolytics-dimension-repository_network_root_nwo | angular/angular.js |
| 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 | 71c92f8b27ec5e9aa6f6477b4e067a4727fc9edb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width