Usually in Typescript, interfaces are used to describe the structure of an object, just as in your example.
classes usually contain actual behaviour code in them. In default configuration (strict: true), Typescript will complain about
classPost{title:string;}
with the following error message:
Property 'title' has no initializer and is not definitely assigned in the constructor.
Additionally, interfaces are purely used in type-checking, since they don't exist in Javascript - they don't get any compilation output! If you create a post.ts file and fill it with your example code from above, your compiled post.js file will only contain
classPost{}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Usually in Typescript, interfaces are used to describe the structure of an object, just as in your example.
class
es usually contain actual behaviour code in them. In default configuration (strict: true
), Typescript will complain aboutwith the following error message:
Additionally,
interface
s are purely used in type-checking, since they don't exist in Javascript - they don't get any compilation output! If you create apost.ts
file and fill it with your example code from above, your compiledpost.js
file will only contain