Title: SUGGESTION: Assert return type is not undefined or null · Issue #15100 · microsoft/TypeScript · GitHub
Open Graph Title: SUGGESTION: Assert return type is not undefined or null · Issue #15100 · microsoft/TypeScript
X Title: SUGGESTION: Assert return type is not undefined or null · Issue #15100 · microsoft/TypeScript
Description: TypeScript Version: 2.3.0-dev.20170407 Code Paste in the following code and scroll to the final two lines: export type Subscription = { dispose: () => void }; export type SubscriberCallbacks
Open Graph Description: TypeScript Version: 2.3.0-dev.20170407 Code Paste in the following code and scroll to the final two lines: export type Subscription = { dispose: () => void }; export type SubscriberCallbacks X Description: TypeScript Version: 2.3.0-dev.20170407 Code Paste in the following code and scroll to the final two lines: export type Subscription = { dispose: () => void }; export type SubscriberCallbacks<...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/15100
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SUGGESTION: Assert return type is not undefined or null","articleBody":"**TypeScript Version:** 2.3.0-dev.20170407\r\n\r\n**Code**\r\nPaste in the following code and scroll to the final two lines:\r\n\r\n```ts\r\nexport type Subscription = { dispose: () => void };\r\n\r\nexport type SubscriberCallbacks\u003cEvents> = {\r\n [event in keyof Events]?: Function;\r\n};\r\n\r\nexport class Subscribers\u003cEvents extends SubscriberCallbacks\u003cEvents>> {\r\n private subscribers: Set\u003cEvents> = new Set\u003cEvents>();\r\n\r\n public add(events: Events): Subscription {\r\n this.subscribers.add(events);\r\n return this.createDisposer(events);\r\n }\r\n\r\n public getNotifier\u003cEventName extends keyof Events>(eventName: EventName): Events[EventName] {\r\n return (...args: any[]) => this.notify(eventName, ...args);\r\n }\r\n\r\n private notify\u003cEventName extends keyof Events>(eventName: EventName, ...args: any[]) {\r\n this.getReleventSubscribers(eventName).forEach((callback: Function) => callback(...args));\r\n }\r\n\r\n private createDisposer(events: Events) {\r\n return { dispose: () => this.subscribers.delete(events) };\r\n }\r\n\r\n private getReleventSubscribers(eventName: keyof Events): Array\u003cEvents[keyof Events]> {\r\n return Array.from(this.subscribers)\r\n .map(events => events[eventName])\r\n .filter(callback => typeof callback !== 'undefined');\r\n }\r\n}\r\n\r\ninterface TestEvents extends SubscriberCallbacks\u003cTestEvents> {\r\n foo?: (bar: number) => void,\r\n baz?: (qux: string) => void,\r\n}\r\n\r\nlet testEventSubScribers = new Subscribers\u003cTestEvents>();\r\n\r\ntestEventSubScribers.add({\r\n foo: (bar: number) => { console.log(bar); },\r\n});\r\ntestEventSubScribers.add({\r\n foo: (bar: number) => { console.log(bar + 'hi'); },\r\n baz: (qux: string) => { console.log(qux + 'hi'); },\r\n});\r\n\r\ntestEventSubScribers.getNotifier('foo')(2);\r\ntestEventSubScribers.getNotifier('baz')('lala');\r\n```\r\n\r\nTo remove the errors I need to assert that the result of the getNotifier call is not undefined.\r\n\r\n```ts\r\ntestEventSubScribers.getNotifier('foo')!(2);\r\ntestEventSubScribers.getNotifier('baz')!('lala');\r\n```\r\n\r\n**Desired behavior:**\r\n\r\nIt'd be nice if I could declare getNotifier as follows (note the final `!`):\r\n\r\n```ts\r\nexport class Subscribers\u003cEvents extends SubscriberCallbacks\u003cEvents>> {\r\n public getNotifier\u003cEventName extends keyof Events>(eventName: EventName): Events[EventName]! {\r\n return (...args: any[]) => this.notify(eventName, ...args);\r\n }\r\n}\r\n```\r\n","author":{"url":"https://github.com/AdamWillden","@type":"Person","name":"AdamWillden"},"datePublished":"2017-04-10T14:46:13Z","url":"https://github.com/microsoft/TypeScript/issues/15100"}
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:96bd3cae-c30d-4bfd-686a-aee68e46538d current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id BC9E:3A347:DCBBF7:125B416:6B00FEAB html-safe-nonce 2f91ee101db18861e277b5566f6d00390df5ce3af610077de829e2cbd046bf8b visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzlFOjNBMzQ3OkRDQkJGNzoxMjVCNDE2OjZCMDBGRUFCIiwidmlzaXRvcl9pZCI6IjI0MTQ2MDYwMTQwMzM3NTU4MTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== visitor-hmac 4d348c8a313b7da0d42fecdef54c0655ef7c659ea597f486737d3cab4edf5b74 hovercard-subject-tag issue:220668409 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/15100/issue_layout twitter:image https://opengraph.githubassets.com/8547050b6a079ece287369558552cf290743a83903dd9ad6a62f813226601cfa/microsoft/TypeScript/issues/15100 twitter:card summary_large_image og:image https://opengraph.githubassets.com/8547050b6a079ece287369558552cf290743a83903dd9ad6a62f813226601cfa/microsoft/TypeScript/issues/15100 og:image:alt TypeScript Version: 2.3.0-dev.20170407 Code Paste in the following code and scroll to the final two lines: export type Subscription = { dispose: () => void }; export type SubscriberCallbacks og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username AdamWillden hostname github.com expected-hostname github.com None e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 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 7dafd017fb7809a839c443dba08622af38e63c09 ui-target full theme-color #1e2327 color-scheme light dark react-app-name issues
URLs of crawlers that visited me.