Skip to content

Idea: improve documentation for strict object-literal assignment checks (including spread-syntax exception) #2240

Closed
@MichaelAllenWarner

Description

@MichaelAllenWarner

Improvement Idea:

It's possible I missed it, but in neither the Handbook nor Reference section of the site did I find a clear explanation of the object-literal "exception" to TypeScript's structural typing system (i.e., that excess properties are not allowed in object literals). There's an example here where the "Object literal may only specify known properties" message appears, but there's no real explanation in the text of the excess-property issue like there was in the old docs. I think this is an important enough feature of the language to be covered explicitly, perhaps on the Object Types page.

Relatedly, I didn't find any mention at all on the website of the spread-syntax exception to that object-literal exception (i.e., that excess properties are allowed in an object literal if they're spread in). Maybe this subtlety could be included as part of a new section on the special treatment that object literals get.

Why:

These details are important but currently difficult to discover.

Alternative ideas:

None that I can think of.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IdeaA way we can improve the site

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions