Skip to content

Suggestion: reflection for interface? #1549

Closed
@vilicvane

Description

@vilicvane

Interface is a useful tool in TypeScript, but sometimes we'll need to write two pieces of almost identical code for intellisense and functionality respectively.

Is it acceptable to add a simple statement for generating part of interface information (properties)?

E.g.

class SomeClass { }

interface ISubFace {
    abc: string;
    def: number;
}

interface IFace {
    str: string;
    num: number;
    obj: SomeClass;
    sub: ISubFace;
}

var faceInfo = reflect IFace;

Would emit:

var SomeClass = (function () {
    function SomeClass() {
    }
    return SomeClass;
})();

var _ISubFaceReflection = {
    abc: 'string',
    def: 'number'
};
var _IFaceReflection = {
    str: 'string',
    num: 'number',
    obj: SomeClass,
    sub: _ISubFaceReflection
};

var faceInfo = _IFaceReflection;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions