|
| 1 | +=== tests/cases/compiler/destructureOfVariableSameAsShorthand.ts === |
| 2 | +// https://github.com/microsoft/TypeScript/issues/38969 |
| 3 | +interface AxiosResponse<T = never> { |
| 4 | +>AxiosResponse : Symbol(AxiosResponse, Decl(destructureOfVariableSameAsShorthand.ts, 0, 0)) |
| 5 | +>T : Symbol(T, Decl(destructureOfVariableSameAsShorthand.ts, 1, 24)) |
| 6 | + |
| 7 | + data: T; |
| 8 | +>data : Symbol(AxiosResponse.data, Decl(destructureOfVariableSameAsShorthand.ts, 1, 36)) |
| 9 | +>T : Symbol(T, Decl(destructureOfVariableSameAsShorthand.ts, 1, 24)) |
| 10 | +} |
| 11 | + |
| 12 | +declare function get<T = never, R = AxiosResponse<T>>(): Promise<R>; |
| 13 | +>get : Symbol(get, Decl(destructureOfVariableSameAsShorthand.ts, 3, 1)) |
| 14 | +>T : Symbol(T, Decl(destructureOfVariableSameAsShorthand.ts, 5, 21)) |
| 15 | +>R : Symbol(R, Decl(destructureOfVariableSameAsShorthand.ts, 5, 31)) |
| 16 | +>AxiosResponse : Symbol(AxiosResponse, Decl(destructureOfVariableSameAsShorthand.ts, 0, 0)) |
| 17 | +>T : Symbol(T, Decl(destructureOfVariableSameAsShorthand.ts, 5, 21)) |
| 18 | +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --)) |
| 19 | +>R : Symbol(R, Decl(destructureOfVariableSameAsShorthand.ts, 5, 31)) |
| 20 | + |
| 21 | +async function main() { |
| 22 | +>main : Symbol(main, Decl(destructureOfVariableSameAsShorthand.ts, 5, 68)) |
| 23 | + |
| 24 | + // These work examples as expected |
| 25 | + get().then((response) => { |
| 26 | +>get().then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) |
| 27 | +>get : Symbol(get, Decl(destructureOfVariableSameAsShorthand.ts, 3, 1)) |
| 28 | +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) |
| 29 | +>response : Symbol(response, Decl(destructureOfVariableSameAsShorthand.ts, 9, 16)) |
| 30 | + |
| 31 | + // body is never |
| 32 | + const body = response.data; |
| 33 | +>body : Symbol(body, Decl(destructureOfVariableSameAsShorthand.ts, 11, 13)) |
| 34 | +>response.data : Symbol(AxiosResponse.data, Decl(destructureOfVariableSameAsShorthand.ts, 1, 36)) |
| 35 | +>response : Symbol(response, Decl(destructureOfVariableSameAsShorthand.ts, 9, 16)) |
| 36 | +>data : Symbol(AxiosResponse.data, Decl(destructureOfVariableSameAsShorthand.ts, 1, 36)) |
| 37 | + |
| 38 | + }) |
| 39 | + get().then(({ data }) => { |
| 40 | +>get().then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) |
| 41 | +>get : Symbol(get, Decl(destructureOfVariableSameAsShorthand.ts, 3, 1)) |
| 42 | +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) |
| 43 | +>data : Symbol(data, Decl(destructureOfVariableSameAsShorthand.ts, 13, 17)) |
| 44 | + |
| 45 | + // data is never |
| 46 | + }) |
| 47 | + const response = await get() |
| 48 | +>response : Symbol(response, Decl(destructureOfVariableSameAsShorthand.ts, 16, 9)) |
| 49 | +>get : Symbol(get, Decl(destructureOfVariableSameAsShorthand.ts, 3, 1)) |
| 50 | + |
| 51 | + // body is never |
| 52 | + const body = response.data; |
| 53 | +>body : Symbol(body, Decl(destructureOfVariableSameAsShorthand.ts, 18, 9)) |
| 54 | +>response.data : Symbol(AxiosResponse.data, Decl(destructureOfVariableSameAsShorthand.ts, 1, 36)) |
| 55 | +>response : Symbol(response, Decl(destructureOfVariableSameAsShorthand.ts, 16, 9)) |
| 56 | +>data : Symbol(AxiosResponse.data, Decl(destructureOfVariableSameAsShorthand.ts, 1, 36)) |
| 57 | + |
| 58 | + // data is never |
| 59 | + const { data } = await get<never>(); |
| 60 | +>data : Symbol(data, Decl(destructureOfVariableSameAsShorthand.ts, 20, 11)) |
| 61 | +>get : Symbol(get, Decl(destructureOfVariableSameAsShorthand.ts, 3, 1)) |
| 62 | + |
| 63 | + // The following did not work as expected. |
| 64 | + // shouldBeNever should be never, but was any |
| 65 | + const { data: shouldBeNever } = await get(); |
| 66 | +>data : Symbol(AxiosResponse.data, Decl(destructureOfVariableSameAsShorthand.ts, 1, 36)) |
| 67 | +>shouldBeNever : Symbol(shouldBeNever, Decl(destructureOfVariableSameAsShorthand.ts, 24, 11)) |
| 68 | +>get : Symbol(get, Decl(destructureOfVariableSameAsShorthand.ts, 3, 1)) |
| 69 | +} |
0 commit comments