1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-03-18 06:10:10 +01:00

Adding content to 104-undefined

This commit is contained in:
syedmouaazfarrukh 2023-02-01 09:24:58 -08:00 committed by Kamran Ahmed
parent 9edcb35acb
commit 12a4be2227
18 changed files with 308 additions and 19 deletions

View File

@ -1 +1,14 @@
# Boolean
# Boolean
`boolean` is a primitive data type in TypeScript that represents a truth value, either true or false.
For example:
```
let isTrue: boolean = true;
let isFalse: boolean = false;
```
Learn more from the following links:
- [Number, String, Boolean, Symbol and Object](https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#number-string-boolean-symbol-and-object)

View File

@ -1 +1,16 @@
# Number
# Number
It is a primitive data type in TypeScript that represents numeric values. It includes both integer and floating-point values.
For example:
```
let intValue: number = 42;
let floatValue: number = 3.14;
```
In TypeScript, numbers can be assigned to variables, passed as arguments to functions, and returned from functions. They are also compatible with arithmetic operators such as +, -, *, /, and % (modulus).
Learn more from the following links:
- [Number, String, Boolean, Symbol and Object](https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#number-string-boolean-symbol-and-object)

View File

@ -1 +1,13 @@
# String
# String
In TypeScript, the string is sequence of char values and also considered as an object.
Syntax:
```
var var_name = new String(string);
```
Learn more from the following links:
- [Number, String, Boolean, Symbol and Object](https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#number-string-boolean-symbol-and-object)

View File

@ -1 +1,18 @@
# Void
# Void
Void is used where there is no data. For example, if a function does not return any value then you can specify void as return type.
Example:
```
function sayHi(): void {
console.log('Hi!')
}
let speech: void = sayHi();
console.log(speech); //Output: undefined
```
Learn more from the following links:
- [void](https://www.typescriptlang.org/docs/handbook/2/functions.html#void)

View File

@ -1 +1,20 @@
# Undefined
# Undefined
In TypeScript, undefined is a built-in type that represents the absence of a value. It can be assigned to variables, properties, or function return values when there is no meaningful value to return.
For example:
```
let x: undefined;
x = undefined; // valid
x = null; // not valid
function doSomething(): undefined {
// ...
return undefined;
}
```
Learn more from the following links:
- [null and undefined](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#null-and-undefined)

View File

@ -1 +1,13 @@
# Null
# Null
In TypeScript, both undefined and null actually have their types named undefined and null respectively. Much like void, theyre not extremely useful on their own:
```
// Not much else we can assign to these variables!
let u: undefined = undefined;
let n: null = null;
```
Learn more from the following links:
- [Null and Undefined](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined)

View File

@ -1 +1,17 @@
# Interface
# Interface
TypeScript allows you to specifically type an object using an interface that can be reused by multiple objects.
Example:
```
interface Publication {
isbn: string;
author: string;
publisher: string;
}
```
Learn more from the following links:
- [Reusable Types (Interfaces)](https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html#reusable-types-interfaces)

View File

@ -1 +1,25 @@
# Class
# Class
In TypeScript, a class is a blueprint for creating objects with specific properties and methods. Classes are a fundamental concept in object-oriented programming. Here is an example of a simple class in TypeScript:
```
class Car {
make: string;
model: string;
year: number;
constructor(make: string, model: string, year: number) {
this.make = make;
this.model = model;
this.year = year;
}
drive() {
console.log(`Driving my ${this.year} ${this.make} ${this.model}`);
}
}
```
Learn more from the following links:
- [Classes](https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html#classes)

View File

@ -1 +1,18 @@
# Enum
# Enum
Enums is not a type-level extension of JavaScript. It allow a developer to define a set of named constants. Using enums can make it easier to document intent, or create a set of distinct cases. TypeScript provides both numeric and string-based enums.
Example:
```
enum Direction {
Up = 1,
Down,
Left,
Right,
}
```
Learn more from the following links:
- [TypeScript - Enums](https://www.typescriptlang.org/docs/handbook/enums.html)

View File

@ -1 +1,7 @@
# Array
# Array
To specify the type of an array like [1, 2, 3], you can use the syntax number[]; this syntax works for any type (e.g. string[] is an array of strings, and so on). You may also see this written as `Array<number>`, which means the same thing. Well learn more about the syntax T<U> when we cover generics.
Learn more from the following links:
- [Arrays](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#arrays)

View File

@ -1 +1,11 @@
# Tuple
# Tuple
A tuple type is another sort of Array type that knows exactly how many elements it contains, and exactly which types it contains at specific positions.
```
type StringNumberPair = [string, number];
```
Learn more from the following links:
- [Tuple Types](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types)

View File

@ -1 +1,19 @@
# Any
# Any
With `any` you can access any properties of it (which will in turn be of type any), call it like a function, assign it to (or from) a value of any type, or pretty much anything else thats syntactically legal:
```
let obj: any = { x: 0 };
// None of the following lines of code will throw compiler errors.
// Using `any` disables all further type checking, and it is assumed
// you know the environment better than TypeScript.
obj.foo();
obj();
obj.bar = 100;
obj = "hello";
const n: number = obj;
```
Learn more from the following links:
- [any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)

View File

@ -1 +1,19 @@
# Object
# Object
To define an object type, we simply list its properties and their types.
For example, heres a function that takes a point-like object:
```
// The parameter's type annotation is an object type
function printCoord(pt: { x: number; y: number }) {
console.log("The coordinate's x value is " + pt.x);
console.log("The coordinate's y value is " + pt.y);
}
printCoord({ x: 3, y: 7 });
```
Learn more from the following links:
- [Number, String, Boolean, Symbol and Object](https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#number-string-boolean-symbol-and-object)
- [Object Types](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#object-types)

View File

@ -1 +1,19 @@
# Unknown
# Unknown
The unknown type represents any value. This is similar to the any type, but is safer because its not legal to do anything with an unknown value:
```
function f1(a: any) {
a.b(); // OK
}
function f2(a: unknown) {
a.b();
Object is of type 'unknown'.
}
```
This is useful when describing function types because you can describe functions that accept any value without having any values in your function body.
Learn more from the following links:
- [Unknown](https://www.typescriptlang.org/docs/handbook/2/functions.html#unknown)

View File

@ -1 +1,28 @@
# Never
# Never
The never type represents the type of values that never occur. For instance, never is the return type for a function expression or an arrow function expression that always throws an exception or one that never returns. Variables also acquire the type never when narrowed by any type guards that can never be true.
The never type is a subtype of, and assignable to, every type; however, no type is a subtype of, or assignable to, never (except never itself). Even any isnt assignable to never.
Examples of functions returning never:
```
// Function returning never must not have a reachable end point
function error(message: string): never {
throw new Error(message);
}
// Inferred return type is never
function fail() {
return error("Something failed");
}
// Function returning never must not have a reachable end point
function infiniteLoop(): never {
while (true) {}
}
```
Learn more from the following links:
- [Never](https://www.typescriptlang.org/docs/handbook/basic-types.html#never)

View File

@ -4,8 +4,8 @@ Type assertions in TypeScript are a way to tell the compiler to treat a value as
There are two syntaxes for type assertions in TypeScript:
1. The "angle-bracket" syntax: <T>value
2. The "as" syntax: value as T
1. The "angle-bracket" syntax: `<T>value`
2. The "as" syntax: value as `T`
For example:

View File

@ -1 +1,23 @@
# Satisfies keyword
# Satisfies Keyword
TypeScript developers are often faced with a dilemma: we want to ensure that some expression matches some type, but also want to keep the most specific type of that expression for inference purposes.
For example:
```
// Each property can be a string or an RGB tuple.
const palette = {
red: [255, 0, 0],
green: "#00ff00",
bleu: [0, 0, 255]
// ^^^^ sacrebleu - we've made a typo!
};
// We want to be able to use array methods on 'red'...
const redComponent = palette.red.at(0);
// or string methods on 'green'...
const greenNormalized = palette.green.toUpperCase();
```
Learn more from the following links:
- [Satisfies Keyword](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html#the-satisfies-operator)

View File

@ -1 +1,26 @@
# Typescript types
# Typescript Types
TypeScript has several built-in types, including:
1. number
2. string
3. boolean
4. any
5. void
6. null and undefined
7. never
8. object
9. symbol
10. Enumerated types (enum)
11. Tuple types
12. Array types
13. Union types
14. Intersection types
15. Type aliases
16. Type assertions
Additionally, you can also create custom types in TypeScript using interfaces, classes, and type aliases.
Learn more from the following links:
- [Transcript - Everyday Types](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html)