Skip to content
New issue

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

Generic extending any becomes generic extending unknown #39471

Closed
gportela85 opened this issue Jul 7, 2020 · 2 comments
Closed

Generic extending any becomes generic extending unknown #39471

gportela85 opened this issue Jul 7, 2020 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@gportela85
Copy link

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

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

@IllusionMH
Copy link
Contributor

This is intended change Type Parameters That Extend any No Longer Act as any

Also see discussion in that PR #29571

@gportela85
Copy link
Author

@IllusionMH thanks

@DanielRosenwasser DanielRosenwasser added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants