Object.keys for a non-instantiated object interface typeEnforcing the type of the indexed members of a Typescript object?Interface type check with TypescriptTypescript interface default valuesTypescript: Interfaces vs TypesTypescript type mapping to expect an object where every property is of a given typeExtending Non Generic Interface with Generic InterfaceTypescript - Force default type for additional properties in interfaceInstantiating an exported TypeScript interfaceDefining an interface for an object which is extended by another interfaceUse an enum to type an index signature of an interface field?

What does “studies need to be taken with more than the usual grain of salt” mean?

What happens to extra attacks after you kill your declared target

Substantivization of "continuum"

What is this second smaller runway next to London City Airport?

Is it possible to commute 34 km (21 miles) daily?

How much caffeine would there be if I reuse tea leaves in a second brewing?

What's the most profitable use for an elemental transmuter?

Temporarily modify the way a counter is displayed in an existing environment

How to answer to the "We do not want to create any precedent" argument in salary negotiation?

Right Ascension for epoch 2000 - physical location?

For a command to increase something, should instructions refer to the "+" key or the "=" key?

Command which removes data left side of ";" (semicolon) on each row

How to tell my research advisor I'd like to drop a class?

How Can I Get A LaTex Table Generated By R's MonteCarlo Package To Work?

How does AT-AT deploy troops?

Can you put L trominos to fill the figure?

Why does the SR-71 Blackbird sometimes have dents in the nose?

What could a technologically advanced but outnumbered alien race do to destroy humanity?

Artificially isolated pawn in the Caro-Kann

Equivalent of phrase 'emu parade' in other English-speaking places

What term can we propose for someone who prioritizes equipment over musicianship?

L tromino tiling

Moisture leaking out of chip in floor tile

Did the Allies reverse the threads on secret microfilm-hiding buttons to thwart the Germans?



Object.keys for a non-instantiated object interface type


Enforcing the type of the indexed members of a Typescript object?Interface type check with TypescriptTypescript interface default valuesTypescript: Interfaces vs TypesTypescript type mapping to expect an object where every property is of a given typeExtending Non Generic Interface with Generic InterfaceTypescript - Force default type for additional properties in interfaceInstantiating an exported TypeScript interfaceDefining an interface for an object which is extended by another interfaceUse an enum to type an index signature of an interface field?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0

















Is there a way to use Object.keys on an interface type itself to get all of the properties of that object type?



export interface Apple
id: number;
name: string;
status: string;


Object.keys(Apple)


Exepected output would be ["id", "name", "status"] like the normal Object.keys. I can't seem to find a way or documentation to accomplish this.










share|improve this question





















  • 2





    As Sam Herrmann mentioned, it sounds impossible. Why do you want to do this?

    – Dakota Jang
    Mar 28 at 21:47











  • I wanted to set a constant at the top of my file that has all the properties of the interface. I iterate through them for the diffing tool I am writing, so I wanted to keep them dynamic in case any properties got added or deleted.

    – C.Programming
    Mar 28 at 21:52











  • Isn't that the reason why we use Typescript? class Foo implements Bar would complain if Foo is missing some implementations in Bar. If you want to prevent modification in runtime, you could try Object.freeze. Though I have a feeling that's not exactly something you are looking for.

    – Dakota Jang
    Mar 31 at 2:08

















0

















Is there a way to use Object.keys on an interface type itself to get all of the properties of that object type?



export interface Apple
id: number;
name: string;
status: string;


Object.keys(Apple)


Exepected output would be ["id", "name", "status"] like the normal Object.keys. I can't seem to find a way or documentation to accomplish this.










share|improve this question





















  • 2





    As Sam Herrmann mentioned, it sounds impossible. Why do you want to do this?

    – Dakota Jang
    Mar 28 at 21:47











  • I wanted to set a constant at the top of my file that has all the properties of the interface. I iterate through them for the diffing tool I am writing, so I wanted to keep them dynamic in case any properties got added or deleted.

    – C.Programming
    Mar 28 at 21:52











  • Isn't that the reason why we use Typescript? class Foo implements Bar would complain if Foo is missing some implementations in Bar. If you want to prevent modification in runtime, you could try Object.freeze. Though I have a feeling that's not exactly something you are looking for.

    – Dakota Jang
    Mar 31 at 2:08













0












0








0








Is there a way to use Object.keys on an interface type itself to get all of the properties of that object type?



export interface Apple
id: number;
name: string;
status: string;


Object.keys(Apple)


Exepected output would be ["id", "name", "status"] like the normal Object.keys. I can't seem to find a way or documentation to accomplish this.










share|improve this question















Is there a way to use Object.keys on an interface type itself to get all of the properties of that object type?



export interface Apple
id: number;
name: string;
status: string;


Object.keys(Apple)


Exepected output would be ["id", "name", "status"] like the normal Object.keys. I can't seem to find a way or documentation to accomplish this.







typescript






share|improve this question














share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 21:38









C.ProgrammingC.Programming

387 bronze badges




387 bronze badges










  • 2





    As Sam Herrmann mentioned, it sounds impossible. Why do you want to do this?

    – Dakota Jang
    Mar 28 at 21:47











  • I wanted to set a constant at the top of my file that has all the properties of the interface. I iterate through them for the diffing tool I am writing, so I wanted to keep them dynamic in case any properties got added or deleted.

    – C.Programming
    Mar 28 at 21:52











  • Isn't that the reason why we use Typescript? class Foo implements Bar would complain if Foo is missing some implementations in Bar. If you want to prevent modification in runtime, you could try Object.freeze. Though I have a feeling that's not exactly something you are looking for.

    – Dakota Jang
    Mar 31 at 2:08












  • 2





    As Sam Herrmann mentioned, it sounds impossible. Why do you want to do this?

    – Dakota Jang
    Mar 28 at 21:47











  • I wanted to set a constant at the top of my file that has all the properties of the interface. I iterate through them for the diffing tool I am writing, so I wanted to keep them dynamic in case any properties got added or deleted.

    – C.Programming
    Mar 28 at 21:52











  • Isn't that the reason why we use Typescript? class Foo implements Bar would complain if Foo is missing some implementations in Bar. If you want to prevent modification in runtime, you could try Object.freeze. Though I have a feeling that's not exactly something you are looking for.

    – Dakota Jang
    Mar 31 at 2:08







2




2





As Sam Herrmann mentioned, it sounds impossible. Why do you want to do this?

– Dakota Jang
Mar 28 at 21:47





As Sam Herrmann mentioned, it sounds impossible. Why do you want to do this?

– Dakota Jang
Mar 28 at 21:47













I wanted to set a constant at the top of my file that has all the properties of the interface. I iterate through them for the diffing tool I am writing, so I wanted to keep them dynamic in case any properties got added or deleted.

– C.Programming
Mar 28 at 21:52





I wanted to set a constant at the top of my file that has all the properties of the interface. I iterate through them for the diffing tool I am writing, so I wanted to keep them dynamic in case any properties got added or deleted.

– C.Programming
Mar 28 at 21:52













Isn't that the reason why we use Typescript? class Foo implements Bar would complain if Foo is missing some implementations in Bar. If you want to prevent modification in runtime, you could try Object.freeze. Though I have a feeling that's not exactly something you are looking for.

– Dakota Jang
Mar 31 at 2:08





Isn't that the reason why we use Typescript? class Foo implements Bar would complain if Foo is missing some implementations in Bar. If you want to prevent modification in runtime, you could try Object.freeze. Though I have a feeling that's not exactly something you are looking for.

– Dakota Jang
Mar 31 at 2:08












2 Answers
2






active

oldest

votes


















2


















This is not possible because TypeScript is only present at development time. Once your code is transpiled to JavaScript, there is no way to reference back to TypeScript types at runtime.






share|improve this answer


























  • That's a bummer. But makes sense. I guess I will have to hardcode the property names and just update it manually if there are any changes. Thank you!

    – C.Programming
    Mar 28 at 21:52


















2


















From documentation I see the following for return value of Object.keys():




An array of strings that represent all the enumerable properties of the given object.




Source: Object.keys().



Which means for example if you have a class what you instantiate from JavaScript then you can get the keys into an array but not from the interface (from TypeScript):






let redApple = new Apple();
let keys = Object.keys(redApple);
let classKeys = Object.keys(Apple);

console.log('keys of the instance', keys);
console.log('keys of the class', classKeys);

function Apple()
this.id = '';
this.name = '';
this.status = '';





We should remember always that at the end TypeScript will be transpiled to JavaScript.






share|improve this answer





























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407235%2fobject-keys-for-a-non-instantiated-object-interface-type%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown


























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2


















    This is not possible because TypeScript is only present at development time. Once your code is transpiled to JavaScript, there is no way to reference back to TypeScript types at runtime.






    share|improve this answer


























    • That's a bummer. But makes sense. I guess I will have to hardcode the property names and just update it manually if there are any changes. Thank you!

      – C.Programming
      Mar 28 at 21:52















    2


















    This is not possible because TypeScript is only present at development time. Once your code is transpiled to JavaScript, there is no way to reference back to TypeScript types at runtime.






    share|improve this answer


























    • That's a bummer. But makes sense. I guess I will have to hardcode the property names and just update it manually if there are any changes. Thank you!

      – C.Programming
      Mar 28 at 21:52













    2














    2










    2









    This is not possible because TypeScript is only present at development time. Once your code is transpiled to JavaScript, there is no way to reference back to TypeScript types at runtime.






    share|improve this answer














    This is not possible because TypeScript is only present at development time. Once your code is transpiled to JavaScript, there is no way to reference back to TypeScript types at runtime.







    share|improve this answer













    share|improve this answer




    share|improve this answer










    answered Mar 28 at 21:42









    Sam HerrmannSam Herrmann

    2,04210 silver badges26 bronze badges




    2,04210 silver badges26 bronze badges















    • That's a bummer. But makes sense. I guess I will have to hardcode the property names and just update it manually if there are any changes. Thank you!

      – C.Programming
      Mar 28 at 21:52

















    • That's a bummer. But makes sense. I guess I will have to hardcode the property names and just update it manually if there are any changes. Thank you!

      – C.Programming
      Mar 28 at 21:52
















    That's a bummer. But makes sense. I guess I will have to hardcode the property names and just update it manually if there are any changes. Thank you!

    – C.Programming
    Mar 28 at 21:52





    That's a bummer. But makes sense. I guess I will have to hardcode the property names and just update it manually if there are any changes. Thank you!

    – C.Programming
    Mar 28 at 21:52













    2


















    From documentation I see the following for return value of Object.keys():




    An array of strings that represent all the enumerable properties of the given object.




    Source: Object.keys().



    Which means for example if you have a class what you instantiate from JavaScript then you can get the keys into an array but not from the interface (from TypeScript):






    let redApple = new Apple();
    let keys = Object.keys(redApple);
    let classKeys = Object.keys(Apple);

    console.log('keys of the instance', keys);
    console.log('keys of the class', classKeys);

    function Apple()
    this.id = '';
    this.name = '';
    this.status = '';





    We should remember always that at the end TypeScript will be transpiled to JavaScript.






    share|improve this answer
































      2


















      From documentation I see the following for return value of Object.keys():




      An array of strings that represent all the enumerable properties of the given object.




      Source: Object.keys().



      Which means for example if you have a class what you instantiate from JavaScript then you can get the keys into an array but not from the interface (from TypeScript):






      let redApple = new Apple();
      let keys = Object.keys(redApple);
      let classKeys = Object.keys(Apple);

      console.log('keys of the instance', keys);
      console.log('keys of the class', classKeys);

      function Apple()
      this.id = '';
      this.name = '';
      this.status = '';





      We should remember always that at the end TypeScript will be transpiled to JavaScript.






      share|improve this answer






























        2














        2










        2









        From documentation I see the following for return value of Object.keys():




        An array of strings that represent all the enumerable properties of the given object.




        Source: Object.keys().



        Which means for example if you have a class what you instantiate from JavaScript then you can get the keys into an array but not from the interface (from TypeScript):






        let redApple = new Apple();
        let keys = Object.keys(redApple);
        let classKeys = Object.keys(Apple);

        console.log('keys of the instance', keys);
        console.log('keys of the class', classKeys);

        function Apple()
        this.id = '';
        this.name = '';
        this.status = '';





        We should remember always that at the end TypeScript will be transpiled to JavaScript.






        share|improve this answer
















        From documentation I see the following for return value of Object.keys():




        An array of strings that represent all the enumerable properties of the given object.




        Source: Object.keys().



        Which means for example if you have a class what you instantiate from JavaScript then you can get the keys into an array but not from the interface (from TypeScript):






        let redApple = new Apple();
        let keys = Object.keys(redApple);
        let classKeys = Object.keys(Apple);

        console.log('keys of the instance', keys);
        console.log('keys of the class', classKeys);

        function Apple()
        this.id = '';
        this.name = '';
        this.status = '';





        We should remember always that at the end TypeScript will be transpiled to JavaScript.






        let redApple = new Apple();
        let keys = Object.keys(redApple);
        let classKeys = Object.keys(Apple);

        console.log('keys of the instance', keys);
        console.log('keys of the class', classKeys);

        function Apple()
        this.id = '';
        this.name = '';
        this.status = '';





        let redApple = new Apple();
        let keys = Object.keys(redApple);
        let classKeys = Object.keys(Apple);

        console.log('keys of the instance', keys);
        console.log('keys of the class', classKeys);

        function Apple()
        this.id = '';
        this.name = '';
        this.status = '';






        share|improve this answer















        share|improve this answer




        share|improve this answer








        edited Mar 28 at 21:58

























        answered Mar 28 at 21:50









        norbitrialnorbitrial

        1,2174 silver badges14 bronze badges




        1,2174 silver badges14 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407235%2fobject-keys-for-a-non-instantiated-object-interface-type%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown









            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현