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

the type error checking bug #38619

Closed
KenFront opened this issue May 17, 2020 · 2 comments
Closed

the type error checking bug #38619

KenFront opened this issue May 17, 2020 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@KenFront
Copy link

TypeScript Version: 3.9.2

**Expected behavior: the two checked results to update properties of object should be same.

**Actual behavior: there is a type error in way 2, but not in way 1.

Code

interface xxx {
    id: string;
    name: string;
    description?: string;
}

const test = (propName: keyof xxx) => {
    const o: xxx = {
        id: '1',
        name: '1',
        description: '1'
    }
    const o2: xxx = {
        id: '1',
        name: '1',
        description: '1'
    }
    // change property way 1
    const o3 = {
        ...o,
        [propName]: o2[propName]
    }

    // change property way 2
    o[propName] = o2[propName]
}
Output
"use strict";
const test = (propName) => {
    const o = {
        id: '1',
        name: '1',
        description: '1'
    };
    const o2 = {
        id: '1',
        name: '1',
        description: '1'
    };
    // change property way 1
    const o3 = Object.assign(Object.assign({}, o), { [propName]: o2[propName] });
    // change property way 2
    o[propName] = o2[propName];
};
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}

Playground Link: Provided

Description: I am not sure the result for both of them should be correct or not. I just think they should be same.

@jcalz
Copy link
Contributor

jcalz commented May 17, 2020

Duplicate of #13948 and #27273

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 17, 2020
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants