We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
inconsistent inference of type of pointer / alias in generic function
https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240701#code/KYDwDg9gTgLgBAMwK4DsDGMCWEV1AQwFswAbYAHgDUA+ACgCg4nFUNsUB5KAQSinwCeALkbMxAHzi1aASjgBeanFQATYAkwpgKmaLFNJtSnhAxgKFQGc4lmFE0BzOAH44lANoBdOEOUX1mtoyADT0cgDeenCYCFK8-AIAdJiW8YK0yOhYOFxpAjIRcFFiaDi2cJCaZlAKLFnsuXyCANxF+sxk8ABu+CS+tDACYMAQsZlsOTxN+e4oSIQARsBQnq0A9GtwEADWgsUdwPAOSPhQKgCM-V2+qNsoEADuKHKKcF3R1gNDI2Os2ZxTBIyWbzJYrdabZZQaD7JidODHU4qABMVxuKDuj2eCiU7xSUkGw1GFQgVWWwLmi2WqzgGy2uwEUQAvkx6EygA
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 } }
(v: unknown) => v is (typeof alias)[number] works, but (v: unknown) => v is (typeof functionOrArray)[number] doesn't.
(v: unknown) => v is (typeof alias)[number]
(v: unknown) => v is (typeof functionOrArray)[number]
Expected alias and functionOrArray to either both work or both not work.
alias
functionOrArray
No response
The text was updated successfully, but these errors were encountered:
Duplicate of #9998.
Sorry, something went wrong.
No branches or pull requests
π Search Terms
inconsistent inference of type of pointer / alias in generic function
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240701#code/KYDwDg9gTgLgBAMwK4DsDGMCWEV1AQwFswAbYAHgDUA+ACgCg4nFUNsUB5KAQSinwCeALkbMxAHzi1aASjgBeanFQATYAkwpgKmaLFNJtSnhAxgKFQGc4lmFE0BzOAH44lANoBdOEOUX1mtoyADT0cgDeenCYCFK8-AIAdJiW8YK0yOhYOFxpAjIRcFFiaDi2cJCaZlAKLFnsuXyCANxF+sxk8ABu+CS+tDACYMAQsZlsOTxN+e4oSIQARsBQnq0A9GtwEADWgsUdwPAOSPhQKgCM-V2+qNsoEADuKHKKcF3R1gNDI2Os2ZxTBIyWbzJYrdabZZQaD7JidODHU4qABMVxuKDuj2eCiU7xSUkGw1GFQgVWWwLmi2WqzgGy2uwEUQAvkx6EygA
π» Code
π Actual behavior
(v: unknown) => v is (typeof alias)[number]
works, but(v: unknown) => v is (typeof functionOrArray)[number]
doesn't.π Expected behavior
Expected
alias
andfunctionOrArray
to either both work or both not work.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: