TypeScript Version: Nightly or 3.9.x
Search Terms: never destructure
Expected behavior: The type of shouldBeNever is never.
Actual behavior: The type of shouldBeNever is any.
The issue also exists for synchronous functions, but the asynchronous example shows that everything works as expected when using Promise.then().
The same issue exists for unknown as well.
Code
interfaceAxiosResponse<T=never>{data: T;}declarefunctionget<T=never,R=AxiosResponse<T>>(): Promise<R>;asyncfunctionmain(){// These work examples as expectedget().then((response)=>{// body is neverconstbody=response.data;})get().then(({ data })=>{// data is never})constresponse=awaitget()// body is neverconstbody=response.data;// data is neverconst{ data }=awaitget<never>();// The following does not work as expected.// shouldBeNever should be never, but is anyconst{data: shouldBeNever}=awaitget();}Output
"use strict";asyncfunctionmain(){// These work examples as expectedget().then((response)=>{// body is neverconstbody=response.data;});get().then(({ data })=>{// data is never});constresponse=awaitget();// body is neverconstbody=response.data;// data is neverconst{ data }=awaitget();// The following does not work as expected.// shouldBeNever should be never, but is anyconst{data: shouldBeNever}=awaitget();}Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"useDefineForClassFields": false,
"alwaysStrict": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"downlevelIteration": false,
"noEmitHelpers": false,
"noLib": false,
"noStrictGenericChecks": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"esModuleInterop": true,
"preserveConstEnums": false,
"removeComments": false,
"skipLibCheck": false,
"checkJs": false,
"allowJs": false,
"declaration": true,
"experimentalDecorators": false,
"emitDecoratorMetadata": false,
"target": "ES2017",
"module": "ESNext"
}
}Playground Link:Provided
TypeScript Version: Nightly or 3.9.x
Search Terms: never destructure
Expected behavior: The type of
shouldBeNeverisnever.Actual behavior: The type of
shouldBeNeverisany.The issue also exists for synchronous functions, but the asynchronous example shows that everything works as expected when using
Promise.then().The same issue exists for
unknownas well.Code
Output
Compiler Options
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true, "strictFunctionTypes": true, "strictPropertyInitialization": true, "strictBindCallApply": true, "noImplicitThis": true, "noImplicitReturns": true, "useDefineForClassFields": false, "alwaysStrict": true, "allowUnreachableCode": false, "allowUnusedLabels": false, "downlevelIteration": false, "noEmitHelpers": false, "noLib": false, "noStrictGenericChecks": false, "noUnusedLocals": false, "noUnusedParameters": false, "esModuleInterop": true, "preserveConstEnums": false, "removeComments": false, "skipLibCheck": false, "checkJs": false, "allowJs": false, "declaration": true, "experimentalDecorators": false, "emitDecoratorMetadata": false, "target": "ES2017", "module": "ESNext" } }Playground Link:Provided