Skip to content

Skip "uncallable" callback arguments when building union signatures (fix for #42558) - #42559

Closed
Nathan Fenner (Nathan-Fenner) wants to merge 2 commits into
microsoft:masterfrom
Nathan-Fenner:nathan-fenner/callback-never-argument-combine-reduce
Closed

Skip "uncallable" callback arguments when building union signatures (fix for #42558)#42559
Nathan Fenner (Nathan-Fenner) wants to merge 2 commits into
microsoft:masterfrom
Nathan-Fenner:nathan-fenner/callback-never-argument-combine-reduce

Conversation

@Nathan-Fenner

Copy link
Copy Markdown
Contributor

Adds a fix for the following case, where the orDefault function can't be used with empty arrays without adding type annotations:

functionorDefault<T,D>(x: T|null,d: D): T|D{if(x===null){returnd;}returnx;}constxs: string[]|null=["a","bc","def"];// y: string[] | never[]consty=orDefault(xs,[]);// ERR: TypeScript 4.1// Each member of the union type // (<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[])// | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])// has signatures, but none of those signatures are compatible with each other. (2349)// ERR: TypeScript 4.2 (dev)// Parameter 'item' implicitly has an 'any' type.(7006)constyThen=y.map(item=>item.length);constyChain=orDefault(xs,[]).map(item=>item.length);

See #42558 for details/background.

@typescript-bot

Copy link
Copy Markdown
Contributor

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@typescript-botTypeScript Bot (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jan 30, 2021
@sandersn

Copy link
Copy Markdown
Member

Nathan Fenner (@Nathan-Fenner) It seems like #42620 addresses the bug as well, and more comprehensively. Does you agree, Wesley Wigham (@weswigham)?

If that's the case, probably we should close this PR.

@Nathan-Fenner

Copy link
Copy Markdown
ContributorAuthor

This test case from this PR might be helpful or interesting to #42620:

constf2: ((ask: (x: string,y?: number)=>void)=>void)|((ask: (x: number,y: never)=>void)=>void)=nullasany;f2((a,b)=>{a;// Ideally, should be stringb;// Ideally, should be number|undefined})

I think #42620 addresses other aspects, but I'm not 100% it handles this (rather uncommon) edge-case. Chucking it in could be useful to track its behavior in the future, anyway

@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants

@Nathan-Fenner@typescript-bot@sandersn