Skip to content

Generic extending any becomes generic extending unknown #39471

Description

TypeScript Version: 3.9.2 and 4.0.0 beta (works fine on 3.8.2 and below)

Search Terms: generic extend any unknown

Expected behavior:
This code should compile just fine

Actual behavior:
I get an error saying Property 'error' does not exist on type 'T'. Because currentBaz: T extends unknown instead extends `any.

Related Issues:

Code

classFoo{publicbar<Textendsany>(baz: T[]): void{baz.forEach(currentBaz=>{if(currentBaz.error){console.log(currentBaz.error);}})}}
Output
"use strict";classFoo{bar(baz){baz.forEach(currentBaz=>{if(currentBaz.error){console.log(currentBaz.error);}});}}
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions