Skip to content

Using special decorators for assertions and constraintsΒ #60093

Closed
@AdamSobieski

Description

@AdamSobieski

πŸ” Search Terms

typescript, inference, decorators, assertions, constraints

βœ… Viability Checklist

⭐ Suggestion

I would like to request a feature involving the use of one or more special decorators for providing even more information about types, functions, and properties.

πŸ“ƒ Motivating Example

@constraint((obj: Foo) => { assert(obj.x > obj.y) })
@constraint((obj: Foo) => { assert(obj.y >= 0) })
@constraint((obj: Foo) => { assert(obj.x >= 0) })
class Foo
{
    x: number;
    y: number;
}

@constraint((obj: ExtendsFoo) => { assert(obj.z >= 0) })
class ExtendsFoo extends Foo
{
    z: number;
}

πŸ’» Use Cases

  1. What do you want to use this for? Even more granular expressiveness about types. functions, and properties would be useful.

  2. What shortcomings exist with current approaches? With one or more special decorators, developers could express many more useful assertions and constraints.

  3. What workarounds are you using in the meantime? Workarounds are situation-dependent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions