๐ Search Terms
"never", "indexed access", "destruct", "property access"
๐ Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries
โฏ Playground Link
https://www.typescriptlang.org/play?&code/MYewdgzgLgBApgDwIYFsAOAbOAuGY4BucATjALx4CuGGMSEehJAUMwPRswACUEAtIjRxgUAcWIhSABQlDiUAJ4wA5ADMQIZTAAmIOAzAhYiAJbQY4GIqEr8RYsoB0ACgBMAZncBOAJTNEqJhwjuogrBzwCEIiJmAA5lYAFnAwEKgpJBKkycRwADQwAEaUsFA5KWZ44HDsnDz8gsKimZIwMiByiiqhWrr6VcYIZrCW1inKdiRObp6%20-sjoWADaahrKALpAA=#code/MYewdgzgLgBApgDwIYFsAOAbOAuGY4BucATjALx4CuGGMSEehJAUMwPRswACUEAtIjRxgUAcWIhSABQlDiUAJ4wA5ADMQIZTAAmIOAzAhYiAJbQY4GIqEr8RYsoB0ACgBMAZncBOAJTNEqJhwjuogrBzwCEIiJmAA5lYAFnAwEKgpJBKkycRwADQwAEaUsFA5KWZ44HDsnDz8gsKimZIwMiByiiqhWrr6VcYIZrCW1inKdiRObp6+-sjoWADaahrKALrhnACSytp0GBAgkdGlyanp8OKt5QXFZyQVBtW13LwCUU1iWW2yJF2rTQ6PTPQbDCxgKwKGwTJgOFwebx+UCQWAAbxgoRgAF9yJFAlggA
๐ป Code
// Given an `example` variable of type `never`:
const example: never = null as never
// this errors correctly
// @ts-expect-error Property 'foo' does not exist on type 'never'.(2339)
example.foo
// expecting the same error here, but there is none
// @ts-expect-error Property 'foo' does not exist on type 'never'.(2339)
example['foo']
// I'd also expect the same error here, but there is none
// @ts-expect-error Property 'foo' does not exist on type 'never'.(2339)
const { foo } = example
๐ Actual behavior
There is an error on the property access (OK), but no error on the indexed access (NOK) and also no error when destructing (NOK)
๐ Expected behavior
I'd expect the same error in all three cases
Additional information about the issue
Had a discussion with @Andarist about this on twitter:
https://x.com/AndaristRake/status/1735078956917723358
๐ Search Terms
"never", "indexed access", "destruct", "property access"
๐ Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries
โฏ Playground Link
https://www.typescriptlang.org/play?&code/MYewdgzgLgBApgDwIYFsAOAbOAuGY4BucATjALx4CuGGMSEehJAUMwPRswACUEAtIjRxgUAcWIhSABQlDiUAJ4wA5ADMQIZTAAmIOAzAhYiAJbQY4GIqEr8RYsoB0ACgBMAZncBOAJTNEqJhwjuogrBzwCEIiJmAA5lYAFnAwEKgpJBKkycRwADQwAEaUsFA5KWZ44HDsnDz8gsKimZIwMiByiiqhWrr6VcYIZrCW1inKdiRObp6%20-sjoWADaahrKALpAA=#code/MYewdgzgLgBApgDwIYFsAOAbOAuGY4BucATjALx4CuGGMSEehJAUMwPRswACUEAtIjRxgUAcWIhSABQlDiUAJ4wA5ADMQIZTAAmIOAzAhYiAJbQY4GIqEr8RYsoB0ACgBMAZncBOAJTNEqJhwjuogrBzwCEIiJmAA5lYAFnAwEKgpJBKkycRwADQwAEaUsFA5KWZ44HDsnDz8gsKimZIwMiByiiqhWrr6VcYIZrCW1inKdiRObp6+-sjoWADaahrKALrhnACSytp0GBAgkdGlyanp8OKt5QXFZyQVBtW13LwCUU1iWW2yJF2rTQ6PTPQbDCxgKwKGwTJgOFwebx+UCQWAAbxgoRgAF9yJFAlggA
๐ป Code
๐ Actual behavior
There is an error on the property access (OK), but no error on the indexed access (NOK) and also no error when destructing (NOK)
๐ Expected behavior
I'd expect the same error in all three cases
Additional information about the issue
Had a discussion with @Andarist about this on twitter:
https://x.com/AndaristRake/status/1735078956917723358