Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type of pointer to object is treated differently from type of object #59104

Open
nvlang opened this issue Jul 2, 2024 · 1 comment
Open

Type of pointer to object is treated differently from type of object #59104

nvlang opened this issue Jul 2, 2024 · 1 comment

Comments

@nvlang
Copy link

nvlang commented Jul 2, 2024

πŸ”Ž Search Terms

inconsistent inference of type of pointer / alias in generic function

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about bugs

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240701#code/KYDwDg9gTgLgBAMwK4DsDGMCWEV1AQwFswAbYAHgDUA+ACgCg4nFUNsUB5KAQSinwCeALkbMxAHzi1aASjgBeanFQATYAkwpgKmaLFNJtSnhAxgKFQGc4lmFE0BzOAH44lANoBdOEOUX1mtoyADT0cgDeenCYCFK8-AIAdJiW8YK0yOhYOFxpAjIRcFFiaDi2cJCaZlAKLFnsuXyCANxF+sxk8ABu+CS+tDACYMAQsZlsOTxN+e4oSIQARsBQnq0A9GtwEADWgsUdwPAOSPhQKgCM-V2+qNsoEADuKHKKcF3R1gNDI2Os2ZxTBIyWbzJYrdabZZQaD7JidODHU4qABMVxuKDuj2eCiU7xSUkGw1GFQgVWWwLmi2WqzgGy2uwEUQAvkx6EygA

πŸ’» Code

export function example<V>(
    functionOrArray:
        | (() => undefined)
        | (V extends string ? V[] : undefined),
) {
    if (Array.isArray(functionOrArray)) { 
        const pointer = functionOrArray; 
        let val: (typeof functionOrArray)[number]; // okay
        let guard1: (v: unknown) => v is (typeof functionOrArray)[number]; // error
        let guard2: (v: unknown) => v is (typeof pointer)[number]; // okay
    }  
}

πŸ™ Actual behavior

(v: unknown) => v is (typeof alias)[number] works, but (v: unknown) => v is (typeof functionOrArray)[number] doesn't.

πŸ™‚ Expected behavior

Expected alias and functionOrArray to either both work or both not work.

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

Duplicate of #9998.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants