Skip to content

This TypeScript code covers various fundamental concepts, including variables, arrays, enums, types, interfaces, generics, classes, inheritance, and more.

Notifications You must be signed in to change notification settings

aokmen/Typescript-Info

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypeScript Code Explanation

Introduction

This TypeScript code covers various fundamental concepts, including variables, arrays, enums, types, interfaces, generics, classes, inheritance, and more.

Variables and Types

Basic Variables

  • message and msg are declared with the string type.
  • count is declared as a number.
  • isTrue is a boolean variable.

Arrays

  • num is an array of numbers, demonstrating array initialization and pushing values.
  • message2 is an array of strings, showcasing string array initialization.

Empty Arrays and ReadOnly Array

  • score and src are examples of empty arrays.
  • readOnlyArray is declared as a read-only number array.

Tuples

  • myTuple demonstrates the usage of a tuple, combining different data types in an array.
  • DE06 is an array of tuples representing student information.

Enums

  • Two examples of enums (Colors and Tshirts) are provided, showcasing their usage.

Any and Unknown Types

  • x is of the any type, allowing dynamic typing.
  • notSure and msg3 demonstrate the unknown type, which is similar to any but requires type assertion.

Void and Never

  • myFunc is a function returning void, meaning it doesn't return any value.
  • The never type is introduced but commented out in an error-generating example.

Union Types

  • d is a variable that can be of type string, number, or boolean.

Type Aliases

  • A type alias named Num is introduced for a union type of string or number.
  • The checkNumber function takes two parameters of type Num and returns a Num.

String Literals

  • pet is a type representing a pet with string literal values "cat" or "dog".

Interface

  • Two examples of interfaces (Person2 and Person) showcase the structure of objects.

Class Constructor and Inheritance

  • The Employee class demonstrates a simple class constructor.
  • The Person and Isci classes show inheritance, with the latter extending the former.

Interface Implementation in Class

  • The Calender interface is implemented by the LMSCalender class.
  • The class contains an array of events, and the addEvents method adds events to it.

Generics

  • The getArray function is a generic function that creates an array based on the provided items.
  • The keyValuePair class demonstrates a generic class with multiple types.

Function Signature of Interface

  • The Sum interface defines a function signature for addition, and it is implemented by the add function.

Conclusion

This TypeScript code provides a comprehensive overview of various language features, helping developers understand and practice TypeScript concepts. Each section demonstrates a specific aspect of the language, making it suitable for learners and developers looking for a quick reference.

About

This TypeScript code covers various fundamental concepts, including variables, arrays, enums, types, interfaces, generics, classes, inheritance, and more.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published