Skip to content

Commit d33b68c

Browse files
Normalize all line endings.
1 parent 795b14c commit d33b68c

12 files changed

+2605
-2605
lines changed

CONTRIBUTING.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
## Contributing
2-
TypeScript-handbook is accepting contributions. If you've submitted a PR for an existing issue, please post a comment in the issue to avoid duplication of effort.
3-
4-
5-
## Housekeeping
6-
Your pull request should:
7-
8-
* Include a description of what your change intends to do
9-
* Have clear commit messages
10-
* e.g. "New Topic", "Fix typo", "Add code samples"
11-
* For code samples, please make sure they compile against the latest released TypeScript compiler version.
1+
## Contributing
2+
TypeScript-handbook is accepting contributions. If you've submitted a PR for an existing issue, please post a comment in the issue to avoid duplication of effort.
3+
4+
5+
## Housekeeping
6+
Your pull request should:
7+
8+
* Include a description of what your change intends to do
9+
* Have clear commit messages
10+
* e.g. "New Topic", "Fix typo", "Add code samples"
11+
* For code samples, please make sure they compile against the latest released TypeScript compiler version.

pages/Basic Types.md

+104-104
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,104 @@
1-
# Introduction
2-
3-
For programs to be useful, we need to be able to work with some of the simplest units of data: numbers, strings, structures, boolean values, and the like. In TypeScript, we support much the same types as you would expected in JavaScript, with a convenient enumeration type thrown in to help things along.
4-
5-
# Boolean
6-
7-
The most basic datatype is the simple true/false value, which JavaScript and TypeScript (as well as other languages) call a `boolean` value.
8-
9-
```TypeScript
10-
var isDone: boolean = false;
11-
```
12-
13-
# Number
14-
15-
As in JavaScript, all numbers in TypeScript are floating point values. These floating point numbers get the type `number`.
16-
17-
```TypeScript
18-
var height: number = 6;
19-
```
20-
21-
# String
22-
23-
Another fundamental part of creating programs in JavaScript for webpages and servers alike is working with textual data. As in other languages, we use the type `string` to refer to these textual datatypes. Just like JavaScript, TypeScript also uses the double quote (") or single quote (') to surround string data.
24-
25-
```TypeScript
26-
var name: string = "bob";
27-
name = 'smith';
28-
```
29-
30-
# Array
31-
32-
TypeScript, like JavaScript, allows you to work with arrays of values. Array types can be written in one of two ways. In the first, you use the type of the elements followed by `[]` to denote an array of that element type:
33-
34-
```TypeScript
35-
var list:number[] = [1, 2, 3];
36-
```
37-
38-
The second way uses a generic array type, `Array<elemType>`:
39-
40-
```TypeScript
41-
var list:Array<number> = [1, 2, 3];
42-
```
43-
44-
# Enum
45-
46-
A helpful addition to the standard set of datatypes from JavaScript is the `enum`. Like languages like C#, an enum is a way of giving more friendly names to sets of numeric values.
47-
48-
```TypeScript
49-
enum Color {Red, Green, Blue};
50-
var c: Color = Color.Green;
51-
```
52-
53-
By default, enums begin numbering their members starting at `0`. You can change this by manually setting the value of one its members. For example, we can start the previous example at `1` instead of `0`:
54-
55-
```TypeScript
56-
enum Color {Red = 1, Green, Blue};
57-
var c: Color = Color.Green;
58-
```
59-
60-
Or, even manually set all the values in the enum:
61-
62-
```TypeScript
63-
enum Color {Red = 1, Green = 2, Blue = 4};
64-
var c: Color = Color.Green;
65-
```
66-
67-
A handy feature of enums is that you can also go from a numeric value to the name of that value in the enum. For example, if we had the value `2` but weren't sure which that mapped to in the `Color` enum above, we could look up the corresponding name:
68-
69-
```TypeScript
70-
enum Color {Red = 1, Green, Blue};
71-
var colorName: string = Color[2];
72-
73-
alert(colorName);
74-
```
75-
76-
# Any
77-
78-
We may need to describe the type of variables that we may not know when we are writing the application. These values may come from dynamic content, e.g. from the user or 3rd party library. In these cases, we want to opt-out of type-checking and let the values pass through compile-time checks. To do so, we label these with the `any` type:
79-
80-
```TypeScript
81-
var notSure: any = 4;
82-
notSure = "maybe a string instead";
83-
notSure = false; // okay, definitely a boolean
84-
```
85-
86-
The `any` type is a powerful way to work with existing JavaScript, allowing you to gradually opt-in and opt-out of type-checking during compilation.
87-
88-
The `any` type is also handy if you know some part of the type, but perhaps not all of it. For example, you may have an array but the array has a mix of different types:
89-
90-
```TypeScript
91-
var list:any[] = [1, true, "free"];
92-
93-
list[1] = 100;
94-
```
95-
96-
# Void
97-
98-
Perhaps the opposite in some ways to `any` is `void`, the absence of having any type at all. You may commonly see this as the return type of functions that do not return a value:
99-
100-
```TypeScript
101-
function warnUser(): void {
102-
alert("This is my warning message");
103-
}
104-
```
1+
# Introduction
2+
3+
For programs to be useful, we need to be able to work with some of the simplest units of data: numbers, strings, structures, boolean values, and the like. In TypeScript, we support much the same types as you would expected in JavaScript, with a convenient enumeration type thrown in to help things along.
4+
5+
# Boolean
6+
7+
The most basic datatype is the simple true/false value, which JavaScript and TypeScript (as well as other languages) call a `boolean` value.
8+
9+
```TypeScript
10+
var isDone: boolean = false;
11+
```
12+
13+
# Number
14+
15+
As in JavaScript, all numbers in TypeScript are floating point values. These floating point numbers get the type `number`.
16+
17+
```TypeScript
18+
var height: number = 6;
19+
```
20+
21+
# String
22+
23+
Another fundamental part of creating programs in JavaScript for webpages and servers alike is working with textual data. As in other languages, we use the type `string` to refer to these textual datatypes. Just like JavaScript, TypeScript also uses the double quote (") or single quote (') to surround string data.
24+
25+
```TypeScript
26+
var name: string = "bob";
27+
name = 'smith';
28+
```
29+
30+
# Array
31+
32+
TypeScript, like JavaScript, allows you to work with arrays of values. Array types can be written in one of two ways. In the first, you use the type of the elements followed by `[]` to denote an array of that element type:
33+
34+
```TypeScript
35+
var list:number[] = [1, 2, 3];
36+
```
37+
38+
The second way uses a generic array type, `Array<elemType>`:
39+
40+
```TypeScript
41+
var list:Array<number> = [1, 2, 3];
42+
```
43+
44+
# Enum
45+
46+
A helpful addition to the standard set of datatypes from JavaScript is the `enum`. Like languages like C#, an enum is a way of giving more friendly names to sets of numeric values.
47+
48+
```TypeScript
49+
enum Color {Red, Green, Blue};
50+
var c: Color = Color.Green;
51+
```
52+
53+
By default, enums begin numbering their members starting at `0`. You can change this by manually setting the value of one its members. For example, we can start the previous example at `1` instead of `0`:
54+
55+
```TypeScript
56+
enum Color {Red = 1, Green, Blue};
57+
var c: Color = Color.Green;
58+
```
59+
60+
Or, even manually set all the values in the enum:
61+
62+
```TypeScript
63+
enum Color {Red = 1, Green = 2, Blue = 4};
64+
var c: Color = Color.Green;
65+
```
66+
67+
A handy feature of enums is that you can also go from a numeric value to the name of that value in the enum. For example, if we had the value `2` but weren't sure which that mapped to in the `Color` enum above, we could look up the corresponding name:
68+
69+
```TypeScript
70+
enum Color {Red = 1, Green, Blue};
71+
var colorName: string = Color[2];
72+
73+
alert(colorName);
74+
```
75+
76+
# Any
77+
78+
We may need to describe the type of variables that we may not know when we are writing the application. These values may come from dynamic content, e.g. from the user or 3rd party library. In these cases, we want to opt-out of type-checking and let the values pass through compile-time checks. To do so, we label these with the `any` type:
79+
80+
```TypeScript
81+
var notSure: any = 4;
82+
notSure = "maybe a string instead";
83+
notSure = false; // okay, definitely a boolean
84+
```
85+
86+
The `any` type is a powerful way to work with existing JavaScript, allowing you to gradually opt-in and opt-out of type-checking during compilation.
87+
88+
The `any` type is also handy if you know some part of the type, but perhaps not all of it. For example, you may have an array but the array has a mix of different types:
89+
90+
```TypeScript
91+
var list:any[] = [1, true, "free"];
92+
93+
list[1] = 100;
94+
```
95+
96+
# Void
97+
98+
Perhaps the opposite in some ways to `any` is `void`, the absence of having any type at all. You may commonly see this as the return type of functions that do not return a value:
99+
100+
```TypeScript
101+
function warnUser(): void {
102+
alert("This is my warning message");
103+
}
104+
```

0 commit comments

Comments
 (0)