{"id":178,"date":"2020-08-20T17:33:31","date_gmt":"2020-08-20T16:33:31","guid":{"rendered":"https:\/\/codetopology.com\/?p=178"},"modified":"2021-07-19T17:32:21","modified_gmt":"2021-07-19T16:32:21","slug":"typescript-interface-vs-class","status":"publish","type":"post","link":"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/","title":{"rendered":"TypeScript Interface Vs Class"},"content":{"rendered":"\n<p>We have covered typescript <a href=\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interfaces\/\">interface<\/a> and <a href=\"https:\/\/codetopology.com\/scripts\/typescript\/classes-in-typescript\/\">class<\/a> in our previous tutorials. <\/p>\n\n\n\n<p>Lets have a closer look at their differences:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>Parameter<\/th><th>TypeScript Class<\/th><th>TypeScript Interface<\/th><\/tr><\/thead><tbody><tr><td>Definition<\/td><td>TypeScript Class is a template which holds methods,variables and provides a skeleton to object.<\/td><td>TypeScript Interface is a blueprint which will tell a deriving class what to implement.<\/td><\/tr><tr><td>Syntax<\/td><td>class &lt;className&gt;{ <br>\/\/body <br> }<\/td><td>interface &lt;iName&gt;{<br>\/\/declarations<br>}<\/td><\/tr><tr><td>Practical Usage<\/td><td>To design a skeleton of modules functionality wise<\/td><td>To hide a complexity from external accessing resource and securing core logic<\/td><\/tr><tr><td>Instantiable<\/td><td>We can Instantiate class using its object<\/td><td>We can not instantiate interface<\/td><\/tr><tr><td>Inheritance<\/td><td>Class supports inheritance by extending other class<\/td><td>Supports inheritance but can not implement other interfaces<\/td><\/tr><tr><td>Functions<\/td><td>Class can have functions and function has complete definition<\/td><td>Interface can have function but it can not define it<\/td><\/tr><tr><td>Constructor<\/td><td>Class can have constructor<\/td><td>NA<\/td><\/tr><tr><td>Access Specifiers<\/td><td>Class can public, private, protected<\/td><td>Interface uses only public access specifier.<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>We have covered typescript interface and class in our previous tutorials. Lets have a closer look at their differences: Parameter TypeScript Class TypeScript Interface Definition&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,10],"tags":[11,9],"class_list":["post-178","post","type-post","status-publish","format-standard","hentry","category-scripts","category-typescript","tag-scripts","tag-typescript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>TypeScript Interface Vs Class - &lt; Code Topology \/&gt;<\/title>\n<meta name=\"description\" content=\"Class can be instanciated but interface can not. Typescript interface can have public access specifiers only. Class can have public,private..\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TypeScript Interface Vs Class - &lt; Code Topology \/&gt;\" \/>\n<meta property=\"og:description\" content=\"Class can be instanciated but interface can not. Typescript interface can have public access specifiers only. Class can have public,private..\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/\" \/>\n<meta property=\"og:site_name\" content=\"&lt; Code Topology \/&gt;\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-20T16:33:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-19T16:32:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codetopology.com\/wp-content\/uploads\/2020\/01\/facebook_profile_image.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"1200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"author\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"author\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/\"},\"author\":{\"name\":\"author\",\"@id\":\"https:\/\/codetopology.com\/#\/schema\/person\/e82a9125be2d13e62c9409c44fadedf1\"},\"headline\":\"TypeScript Interface Vs Class\",\"datePublished\":\"2020-08-20T16:33:31+00:00\",\"dateModified\":\"2021-07-19T16:32:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/\"},\"wordCount\":159,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/codetopology.com\/#\/schema\/person\/e82a9125be2d13e62c9409c44fadedf1\"},\"keywords\":[\"scripts\",\"typescript\"],\"articleSection\":[\"Scripts\",\"Typescript\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/\",\"url\":\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/\",\"name\":\"TypeScript Interface Vs Class - &lt; Code Topology \/&gt;\",\"isPartOf\":{\"@id\":\"https:\/\/codetopology.com\/#website\"},\"datePublished\":\"2020-08-20T16:33:31+00:00\",\"dateModified\":\"2021-07-19T16:32:21+00:00\",\"description\":\"Class can be instanciated but interface can not. Typescript interface can have public access specifiers only. Class can have public,private..\",\"breadcrumb\":{\"@id\":\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/codetopology.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scripts\",\"item\":\"https:\/\/codetopology.com\/category\/scripts\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Typescript\",\"item\":\"https:\/\/codetopology.com\/category\/scripts\/typescript\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"TypeScript Interface Vs Class\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codetopology.com\/#website\",\"url\":\"https:\/\/codetopology.com\/\",\"name\":\"&lt; Code Topology \/&gt;\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/codetopology.com\/#\/schema\/person\/e82a9125be2d13e62c9409c44fadedf1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codetopology.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/codetopology.com\/#\/schema\/person\/e82a9125be2d13e62c9409c44fadedf1\",\"name\":\"author\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/codetopology.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5bdbb3965858c4dc88faa09e5c57c06449c56405cb5f640ab09c6a8e30ecbb42?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5bdbb3965858c4dc88faa09e5c57c06449c56405cb5f640ab09c6a8e30ecbb42?s=96&d=mm&r=g\",\"caption\":\"author\"},\"logo\":{\"@id\":\"https:\/\/codetopology.com\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"TypeScript Interface Vs Class - &lt; Code Topology \/&gt;","description":"Class can be instanciated but interface can not. Typescript interface can have public access specifiers only. Class can have public,private..","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/","og_locale":"en_GB","og_type":"article","og_title":"TypeScript Interface Vs Class - &lt; Code Topology \/&gt;","og_description":"Class can be instanciated but interface can not. Typescript interface can have public access specifiers only. Class can have public,private..","og_url":"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/","og_site_name":"&lt; Code Topology \/&gt;","article_published_time":"2020-08-20T16:33:31+00:00","article_modified_time":"2021-07-19T16:32:21+00:00","og_image":[{"width":1200,"height":1200,"url":"https:\/\/codetopology.com\/wp-content\/uploads\/2020\/01\/facebook_profile_image.png","type":"image\/png"}],"author":"author","twitter_card":"summary_large_image","twitter_misc":{"Written by":"author","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/#article","isPartOf":{"@id":"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/"},"author":{"name":"author","@id":"https:\/\/codetopology.com\/#\/schema\/person\/e82a9125be2d13e62c9409c44fadedf1"},"headline":"TypeScript Interface Vs Class","datePublished":"2020-08-20T16:33:31+00:00","dateModified":"2021-07-19T16:32:21+00:00","mainEntityOfPage":{"@id":"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/"},"wordCount":159,"commentCount":0,"publisher":{"@id":"https:\/\/codetopology.com\/#\/schema\/person\/e82a9125be2d13e62c9409c44fadedf1"},"keywords":["scripts","typescript"],"articleSection":["Scripts","Typescript"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/","url":"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/","name":"TypeScript Interface Vs Class - &lt; Code Topology \/&gt;","isPartOf":{"@id":"https:\/\/codetopology.com\/#website"},"datePublished":"2020-08-20T16:33:31+00:00","dateModified":"2021-07-19T16:32:21+00:00","description":"Class can be instanciated but interface can not. Typescript interface can have public access specifiers only. Class can have public,private..","breadcrumb":{"@id":"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codetopology.com\/scripts\/typescript\/typescript-interface-vs-class\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codetopology.com\/"},{"@type":"ListItem","position":2,"name":"Scripts","item":"https:\/\/codetopology.com\/category\/scripts\/"},{"@type":"ListItem","position":3,"name":"Typescript","item":"https:\/\/codetopology.com\/category\/scripts\/typescript\/"},{"@type":"ListItem","position":4,"name":"TypeScript Interface Vs Class"}]},{"@type":"WebSite","@id":"https:\/\/codetopology.com\/#website","url":"https:\/\/codetopology.com\/","name":"&lt; Code Topology \/&gt;","description":"","publisher":{"@id":"https:\/\/codetopology.com\/#\/schema\/person\/e82a9125be2d13e62c9409c44fadedf1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codetopology.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/codetopology.com\/#\/schema\/person\/e82a9125be2d13e62c9409c44fadedf1","name":"author","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/codetopology.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5bdbb3965858c4dc88faa09e5c57c06449c56405cb5f640ab09c6a8e30ecbb42?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5bdbb3965858c4dc88faa09e5c57c06449c56405cb5f640ab09c6a8e30ecbb42?s=96&d=mm&r=g","caption":"author"},"logo":{"@id":"https:\/\/codetopology.com\/#\/schema\/person\/image\/"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/codetopology.com\/wp-json\/wp\/v2\/posts\/178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codetopology.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codetopology.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codetopology.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codetopology.com\/wp-json\/wp\/v2\/comments?post=178"}],"version-history":[{"count":4,"href":"https:\/\/codetopology.com\/wp-json\/wp\/v2\/posts\/178\/revisions"}],"predecessor-version":[{"id":469,"href":"https:\/\/codetopology.com\/wp-json\/wp\/v2\/posts\/178\/revisions\/469"}],"wp:attachment":[{"href":"https:\/\/codetopology.com\/wp-json\/wp\/v2\/media?parent=178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codetopology.com\/wp-json\/wp\/v2\/categories?post=178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codetopology.com\/wp-json\/wp\/v2\/tags?post=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}