Skip to content

No validation while destructuring array in object of definite type #51148

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

Closed
carino1 opened this issue Oct 12, 2022 · 2 comments
Closed

No validation while destructuring array in object of definite type #51148

carino1 opened this issue Oct 12, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@carino1
Copy link

carino1 commented Oct 12, 2022

Bug Report

🔎 Search Terms

google
stackoverflow
https://github.com/Microsoft/TypeScript/wiki/FAQ#what-is-structural-typing

🕗 Version & Regression Information

This is the behavior in every version I tried, and I reviewed all the FAQ for entries

⏯ Playground Link

[[<!--
A link to a TypeScript Playground "Share" link which shows this behavior

The TypeScript Workbench can be used for more complex setups, try
https://www.typescriptlang.org/dev/bug-workbench/

As a last resort, you can link to a repo, but these will be slower for us to investigate.
-->
Playground link with relevant code](https://www.typescriptlang.org/play?noUncheckedIndexedAccess=true&target=99&noImplicitOverride=false#code/JYOwLgpgTgZghgYwgAgLIE8AqEDOYCS4E8SyA3gFDLXJwD8AXMnlKAObIA+yIArgDb8A3FRoAjRszCsQHbn0EiAvhQoQAHgAcA9lDDIYvEAjDBtIZAFssuMADEjJsyAAUFAJRMM2PIUgkUShpkBHM8ZDE4HAgvG18iAOQAXnJRYOo4JgByAEYsgBo09LFsgCYCoqURItCQcLgoKGTkAG1kXIL28uQAXWrgqAgwXigLIPTqADppyOjCianphqhKiiUgA)](https://www.typescriptlang.org/play?noUncheckedIndexedAccess=true&target=99&noImplicitOverride=false#code/JYOwLgpgTgZghgYwgAgLIE8AqEDOYCS4E8SyA3gFDLXJwD8AXMnlKAObIA+yIArgDb8A3FRoAjRszCsQHbn0EiAvhQoQAHgAcA9lDDIYvEAjDBtIZAFssuMADEjJsyAAUFAJRMM2PIUgkUShpkBHM8ZDE4HAgvG18iAOQAXnJRYOo4JgByAEYsgBo09LFsgCYCoqURItCQcLgoKGTkAG1kXIL28uQAXWrgqAgwXigLIPTqADppyOjCianphqhKiiUgA)

💻 Code

interface MyTestInteface {
    a?: string | null;
    b?: string | null;
}

export function myTestFunction(
): MyTestInteface {
    const base: MyTestInteface = {
        a: '1',
        b: '2',
    };

    const arr = [ '1', '2' ];

    return {
        ...base,
        ...arr
    }
}

🙁 Actual behavior

No typescript error in return statement

🙂 Expected behavior

Array is destructuring in object, that should be MyTestInteface. Expecting an error here

@MartinJohns
Copy link
Contributor

Duplicate of #49667 / #9726.

And the syntax you're using is called "spreading", not destructuring.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 12, 2022
@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