0
0
Typescriptprogramming~10 mins

Interface declaration syntax in Typescript - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Interface declaration syntax
Start Interface Declaration
Write 'interface' keyword
Name the Interface
Open Curly Brace '{'
Declare Properties and Methods
Close Curly Brace '}'
Interface Ready
This flow shows the steps to declare an interface: start with the keyword, name it, add properties/methods inside braces, then finish.
Execution Sample
Typescript
interface Person {
  name: string;
  age: number;
  greet(): void;
}
Declares an interface named Person with two properties and one method signature.
Execution Table
StepActionCode PartResult
1Start interface declarationinterfaceBegin interface block
2Name the interfacePersonInterface named Person created
3Open interface body{Start listing members
4Declare propertyname: string;Property 'name' of type string added
5Declare propertyage: number;Property 'age' of type number added
6Declare method signaturegreet(): void;Method 'greet' with no return added
7Close interface body}Interface declaration complete
💡 Interface declaration ends after closing brace '}'
Variable Tracker
VariableStartAfter Step 4After Step 5After Step 6Final
Interface NameNonePersonPersonPersonPerson
PropertiesNonename: stringname: string, age: numbername: string, age: numbername: string, age: number
MethodsNoneNoneNonegreet(): voidgreet(): void
Key Moments - 3 Insights
Why do we use a semicolon after each property or method in the interface?
Each property or method declaration ends with a semicolon to separate it from the next one, as shown in steps 4, 5, and 6 in the execution_table.
Does the interface contain actual code for methods?
No, interfaces only declare method signatures without implementation, as seen in step 6 where 'greet(): void;' is declared without a body.
Can we declare variables inside an interface?
No, interfaces declare the shape of objects with properties and method signatures, not variables or executable code.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the interface name after step 2?
Agreet
Binterface
CPerson
DNone
💡 Hint
Check the 'Code Part' and 'Result' columns at step 2 in the execution_table.
At which step does the interface declaration complete?
AStep 7
BStep 5
CStep 6
DStep 4
💡 Hint
Look for the step where the closing brace '}' is processed in the execution_table.
If we remove the semicolon after 'age: number', what would happen?
AMethod 'greet' becomes a property
BNo effect, code runs fine
CSyntax error, interface won't compile
DInterface name changes
💡 Hint
Semicolons are optional in TypeScript interfaces due to automatic semicolon insertion on newlines; the code compiles fine.
Concept Snapshot
interface InterfaceName {
  propertyName: type;
  methodName(): returnType;
}
- Use 'interface' keyword
- Declare properties with types
- Declare method signatures only
- End each declaration with semicolon
- No method bodies inside interface
Full Transcript
This visual execution traces how to declare an interface in TypeScript. First, the keyword 'interface' starts the declaration. Then you name the interface, for example, 'Person'. Next, open curly braces '{' to begin listing properties and methods. Each property like 'name: string;' and 'age: number;' is declared with a type and ends with a semicolon. Methods like 'greet(): void;' declare the signature without code. Finally, close the interface with '}'. The interface describes the shape of an object but does not contain executable code. Semicolons separate each declaration. This step-by-step helps beginners see how interfaces are built and why syntax matters.