Relative Content

Tag Archive for typescripttypescript-generics

Extract arguments type from function intersection based on first argument value

Given https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKhDOwoF4oAo0QG7AFxQHIBjAewDsAzASwCcBbCAEwIBooBDGgc3gH0AGfAG8oJLBBoB3GlWAR8AIxIkANhHZkoAXwCUKAHxQsJKoz0AydJhz5iGohDXM9yQ8dM6A3AChvoSFAAogAewDTsRMAAgtwAPDBsgYaoMFAQoRBkjPDo2HhBbJw8+FSUElAACi5uJoxQAPyVUPhk2BI+-tAhYRHAAMLk1PRMMTzxybBpGVk51vnEg7QMzIXcJWU0UACq1Ua1DdvNUK3iND5+4F3iZMAVnOwMcjTw8YkTqelyM7k2UKUU5RggTYADowUV4OsAZtRvBdu46o00ECpl9skEDrCjicJHoWm0zr4APRE44kJCSEg0ADWpS4FwCA0oSyYd3CjwkOVQgWut3uHOe8QQwDYC2Zw2Y+gA2vwALrnEnsFTwEhkilU2lkemdJrc0LhSKjIWIUWkcXLAj6c46qJkckACwkMBoIBQQX1vSZQ2WsONwCtQA

TypeScript is not throwing a type error when function return type doesn’t match generic type

I’m having trouble with typescript not throwing type errors in my code. I have a function registerIpcChannel that registers an IPC channel with a specific handler. The handler should match the types defined in the IpcChannel interface. This works for the most part, however, when I intentionally return undefined or null from the handler, typescript does not throw a type error as expected. Here’s a simplified version of my code: