Title: Expose ControlConfig type under @angular/forms · Issue #46570 · angular/angular · GitHub
Open Graph Title: Expose ControlConfig type under @angular/forms · Issue #46570 · angular/angular
X Title: Expose ControlConfig type under @angular/forms · Issue #46570 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? forms Is this a regression? No Description Expose ControlConfig type in public API export type ControlConfig
Open Graph Description: Which @angular/* package(s) are the source of the bug? forms Is this a regression? No Description Expose ControlConfig type in public API export type ControlConfig
X Description: Which @angular/* package(s) are the source of the bug? forms Is this a regression? No Description Expose ControlConfig type in public API export type ControlConfig<T> = [T|FormControlState<...
Opengraph URL: https://github.com/angular/angular/issues/46570
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Expose ControlConfig type under @angular/forms","articleBody":"### Which @angular/* package(s) are the source of the bug?\r\n\r\nforms\r\n\r\n### Is this a regression?\r\n\r\nNo\r\n\r\n### Description\r\n\r\nExpose `ControlConfig` type in public API\r\n\r\n```typescript\r\nexport type ControlConfig\u003cT> = [T|FormControlState\u003cT>, (ValidatorFn|(ValidatorFn[]))?, (AsyncValidatorFn|AsyncValidatorFn[])?];\r\n```\r\nhttps://github.com/angular/angular/blob/main/packages/forms/src/form_builder.ts#L32\r\n\r\nSo, `ControlConfig` type can be consumed within applications like this:\r\n`import { ControlConfig } from '@angular/forms';`\r\n\r\n### Please provide a link to a minimal reproduction of the bug\r\n\r\n- `> npx @angular/cli@next new web-apps --create-application false --strict`\r\n- `> cd web-apps`\r\n- `> yarn ng generate app admin-console --routing --style css`\r\n- Edit `projects/admin-console/src/app/app.component.ts` and replace with this code\r\n\r\n```typescript\r\nimport { ChangeDetectionStrategy, Component } from '@angular/core';\r\nimport {\r\n AsyncValidatorFn,\r\n FormControl,\r\n FormControlState,\r\n FormGroup,\r\n NonNullableFormBuilder,\r\n ValidatorFn,\r\n Validators,\r\n} from '@angular/forms';\r\n\r\ninterface Credentials {\r\n email: string;\r\n password: string;\r\n}\r\n\r\ninterface LoginCredentialsInitialReactiveFormGroup {\r\n email: ControlConfig\u003cstring>;\r\n password: ControlConfig\u003cstring>;\r\n}\r\n\r\ninterface LoginCredentialsReactiveFormGroup {\r\n email: FormControl\u003cstring>;\r\n password: FormControl\u003cstring>;\r\n}\r\n\r\n@Component({\r\n selector: 'app-root',\r\n templateUrl: './app.component.html',\r\n styleUrls: ['./app.component.css'],\r\n changeDetection: ChangeDetectionStrategy.OnPush,\r\n})\r\nexport class AppComponent {\r\n title = 'admin-console';\r\n\r\n public loginFormGroup: FormGroup\u003cLoginCredentialsReactiveFormGroup>;\r\n\r\n constructor(private readonly fb: NonNullableFormBuilder) {\r\n this.loginFormGroup =\r\n this.fb.group\u003cLoginCredentialsInitialReactiveFormGroup>({\r\n email: ['', [Validators.required]],\r\n password: ['', [Validators.required]],\r\n });\r\n\r\n const afterSubmitData: Credentials = this.loginFormGroup.getRawValue();\r\n }\r\n}\r\n```\r\n\r\n\r\n### Please provide the exception or error you saw\r\n\r\n`Cannot find name 'ControlConfig'. ts(2304)`\r\n\r\n### Please provide the environment you discovered this bug in (run `ng version`)\r\n\r\n```\r\nAngular CLI: 14.1.0-next.3\r\nNode: 16.15.1\r\nPackage Manager: npm 8.11.0 \r\nOS: darwin arm64\r\n\r\nAngular: 14.0.4\r\n... animations, common, compiler, compiler-cli, core, forms\r\n... platform-browser, platform-browser-dynamic, router\r\n\r\nPackage Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect 0.1401.0-next.3\r\n@angular-devkit/build-angular 14.1.0-next.3\r\n@angular-devkit/core 14.1.0-next.3\r\n@angular-devkit/schematics 14.1.0-next.3\r\n@angular/cli 14.1.0-next.3\r\n@schematics/angular 14.1.0-next.3\r\nrxjs 7.5.5\r\ntypescript 4.7.4\r\n```\r\n### Anything else?\r\n\r\nAfter you review the reproduction example, Could you describe an approach where we can achieve the same results with 1 interface instead of 3 interfaces?\r\nPerhaps some typescript utility types could be provided out of the box.\r\nExample:\r\n```typescript\r\nexport type ControlsOf\u003cT extends Record\u003cstring, any>> = {\r\n [K in keyof T]: T[K] extends Record\u003cany, any>\r\n ? FormGroup\u003cControlsOf\u003cT[K]>>\r\n : FormControl\u003cT[K]>;\r\n};\r\n```\r\nas mentioned in https://netbasal.com/typed-reactive-forms-in-angular-no-longer-a-type-dream-bf6982b0af28","author":{"url":"https://github.com/prabh-62","@type":"Person","name":"prabh-62"},"datePublished":"2022-06-28T23:20:04Z","url":"https://github.com/angular/angular/issues/46570"}
| 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:16f483e8-b4ba-81fb-378c-962db92a4983 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D082:20AA01:F84192:13E0F58:6B00FD84 |
| html-safe-nonce | d0046f9e95f6816b79e88d88b820b0a52b4691cadb8a470b9e365dfd66bc139f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDgyOjIwQUEwMTpGODQxOTI6MTNFMEY1ODo2QjAwRkQ4NCIsInZpc2l0b3JfaWQiOiI2MzQzOTcxMzE4NTQyNjk1ODEyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8bdb29284b7000d69d16a4727c3986dae8f9c230d473bf34788b8e18ee86b8ce |
| hovercard-subject-tag | issue:1288001412 |
| 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/46570/issue_layout |
| twitter:image | https://opengraph.githubassets.com/97033ed406d58013eef3135059d9361dcabd22f4dea3af6f89924e89a6b26c9a/angular/angular/issues/46570 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/97033ed406d58013eef3135059d9361dcabd22f4dea3af6f89924e89a6b26c9a/angular/angular/issues/46570 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? forms Is this a regression? No Description Expose ControlConfig type in public API export type ControlConfig |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | prabh-62 |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width