Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds typescript language basic data types #121

Merged
merged 4 commits into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS_LIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
| [Reza Bojnordi](https://github.com/rezabojnordi)|1|
| [AzerothA](https://github.com/AzerothA)|1|
| [Arman](https://github.com/arman324)|1|
| [Morteza Heydari](https://github.com/MortezaHeydari97)|1|
| [Jadi Mirmirani](https://github.com/jadijadi)|1|
| [Ali Naderi](https://github.com/khod-naderi)|1|
| [AmirJEY](https://github.com/AmirJey)|1|
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Special Thanks from [Parsa](https://github.com/parsampsh) & [Amirhossein](https:
---

- [Tcl](/Tcl) - Added By <img src="https://github.com/Ja7adR.png?size=25" width="25" height="25" /> [Javad Rajabzade](https://github.com/Ja7adR)
- [Typescript](/Typescript) - Added By <img src="https://github.com/BlackIQ.png?size=25" width="25" height="25" /> [Amirhossein Mohammadi](https://github.com/BlackIQ)
- [Typescript](/Typescript) - Added By <img src="https://github.com/MortezaHeydari97.png?size=25" width="25" height="25" /> [Morteza Heydari](https://github.com/MortezaHeydari97), <img src="https://github.com/BlackIQ.png?size=25" width="25" height="25" /> [Amirhossein Mohammadi](https://github.com/BlackIQ)


### V
Expand Down
81 changes: 81 additions & 0 deletions Typescript/examples/dataTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Here is a complete exmaple of typescript data types
*/


/* =============================== Brief Examples =============================== */

let name: string = "Morteza" // string data type
let isAlive: boolean = true // boolean data type
let rand: number = 124 // number data type

let obj: object = {} // object data type
let arr: any[] = [] // array of elements via any data type
let tpl: [string, number] = ["test", 10] // tuple data type

let empt: null = null // null data type
let und: undefined = undefined // undefined data type
let vd: void = undefined // void data type

let an: any = "any" // any data type



/// String Data Type
let fullName: string = "Morteza Heydari"
let color = "dodgerblue"
let multiLineTxt: string = `
The first line of string
The seconds line of string
The third line of string
`


/// Number Data Type
let age: number = 24
let bgNum: bigint = 100n
let negNum: number = -1000


/// Object Data Type
let userInfo: {firstName: string, lastName: string, age: number, fullName: (a: string, b: string) => string} = {
firstName: 'Morteza',
lastName: 'Heydari',
age: 24,
fullName: function(fName: string, lastName: string) {
return `${fName} ${lastName}`
}
}


/// Array Data Type
let strGroup: string[] = ["number_1", "number_2", "number_3", "number_4"] // An array of strings
let numGroup: number[] = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] // An array of numbers
let mixedGroup: any[] = ["mixed", 123, false, null, {year: 2021, bornIn: 1997}, ["this", "is", "another", "member"]] // A mixed array

// type {firtName: string, lastName: string}[] is an array of {firtName: string, lastName: string} object that you can write it also like so:
let diffArr: Array<{firtName: string, lastName: string}> = [
{firtName: 'Morteza', lastName: 'Heydari'},
{firtName: 'Ali', lastName: 'Mousavi'},
{firtName: 'Ahmad', lastName: 'Azad'}
] // Array<elemType> is called generics


/// Tuple Data Type : Tuple is a fixed sized array that all elements' types are specified
let fixedArr: [string, boolean, undefined, number] = ["tuple", true, undefined, Infinity]



/* ===== Notes ===== */
// If you try to change one of the types, you will get an error unless than any data type. like this:
let strTyped: string = "Try to change my type"
strTyped = 10 // Now you will see the error

let anyTyped: any = "Now you can change my type !"
anyTyped = true // Type of anyTyped variable is changed to boolean
anyTyped = 200 // And now type of the anyTyped variable is changed to number




// =*=*=*=*=*=*=*=*=*=*=*=*=* Author: Morteza Heydari - Good Luck *=*=*=*=*=*=*=*=*=*=*=*=*= \\
16 changes: 11 additions & 5 deletions Typescript/info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"creators": {
"title": "Amirhossein Mohammadi",
"link": "https://github.com/BlackIQ"
}
}
"creators": [
{
"title": "Morteza Heydari",
"link": "https://github.com/MortezaHeydari97"
},
{
"title": "Amirhossein Mohammadi",
"link": "https://github.com/BlackIQ"
}
]
}
3 changes: 2 additions & 1 deletion tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@
│ ├── books.md
│ ├── courses.md
│ ├── examples
│ │ ├── dataTypes.ts
│ │ └── typescript.ts
│ ├── info.json
│ └── resources.md
Expand Down Expand Up @@ -787,4 +788,4 @@
├── auto-gen.py
└── tree.txt

191 directories, 596 files
191 directories, 597 files