Skip to content

Commit

Permalink
integrating typescript and note about variadic types
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-paul committed Jul 15, 2020
1 parent 5c71c80 commit 5136845
Show file tree
Hide file tree
Showing 16 changed files with 439 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ The compiled CSS will be
color: #ff0;
}
```
### Nested ampersand - Very useful

The cool thing about ampersands is that they don't only have to be at the beginning of a nested style definition.

### Wherever you put an ampersand into your Sass selector definitions, it is interpreted to mean the parent scope of the current style being defined.

The cool thing about ampersands is that they don't only have to be at the beginning of a nested style definition. Wherever you put an ampersand into your Sass selector definitions, it is interpreted to mean the parent scope of the current style being defined.
An application of the above is - sometimes you need to define a style that takes the context of the existing style, but only applies in a special case. For example, what if we need a different border treatment for our `.hoverable`element when the parent class is `.special`

The SASS without a nested "&" would be below

```css
.hoverable {
.hoverable {
color: #fff;
&:hover {
color: #ff0;
Expand All @@ -67,7 +71,7 @@ Doing this required us to step out of our .hoverable selector and then re-define
But with the ampersand, Sass allows us to do the same thing without leaving the scope of the .hoverable selector:

```css
.hoverable {
.hoverable {
color: #fff;
&:hover {
color: #ff0;
Expand Down
Empty file modified CSS/Chain-Selector/ampersand-generated-css-example.md
100644 → 100755
Empty file.
Empty file modified CSS/Chain-Selector/mixin-with-ampersand-best-practice-1.md
100644 → 100755
Empty file.
Empty file modified CSS/Chain-Selector/multiple-class-selector-with-ampersand-1.md
100644 → 100755
Empty file.
Empty file modified CSS/Chain-Selector/multiple-class-selector-with-ampersand-2.md
100644 → 100755
Empty file.
Empty file modified CSS/Chain-Selector/scss-multiple-class-selector.md
100644 → 100755
Empty file.
Empty file modified CSS/SCSS/adjacent-sibling-selectors.md
100644 → 100755
Empty file.
Empty file modified CSS/SCSS/ampersand-vs-dots.md
100644 → 100755
Empty file.
Empty file modified CSS/SCSS/mixin-basics-2.md
100644 → 100755
Empty file.
3 changes: 0 additions & 3 deletions Javascript/map-set-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ map.set(0, 'val-1')
console.log(map) // => Map { 0 => 'val-1' }





// EXAMPLE-2 Map can also use objects as keys

let john = { name: "John" };
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Awesome JavaScript Interviews

A collection of super-popular Interview questions, along with answers, and some code-snippets that I am putting together for myself while preparing for JavaScript interviews. Many of these questions are what I have actually faced in real interview. It is by no means comprehensive, and the answers are relatively short ( and for each of the concepts, there are probably better and/or more in depth coverage in the web), but I see this repo as reference tool, so I can continue a technical talk with the interviewer for two to three hours.
A collection of super-popular Interview questions, along with answers, and some code-snippets that I was putting together for myself while preparing for JavaScript interviews. Many of these questions are what I have actually faced in real interview. It is by no means comprehensive, and the answers are relatively short ( and for each of the concepts, there are probably better and/or more in depth coverage in the web), but I see this repo as reference tool, so I can continue a technical talk with the interviewer for two to three hours.

There are many fantastic resources for JavaScript interview questions, videos, and blog posts on the web and that I have drawn from. I will cite as many as I can throughout so that additional information on each list item can be easily found.

Expand Down
33 changes: 33 additions & 0 deletions Typscript/Variadic_Types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
In TypeScript 4.0 beta you could try variadic types.
This will let us decrease the number of overloads when declaring types for functions with variadic number of arguments
Typescript give types to higher-order functions that take a variable number of parameters.
Functions like this include concat, apply, curry, compose and almost any decorator that wraps a function.
https://github.com/microsoft/TypeScript/pull/39094
A variadic elemement is a spread element of the form ...T, where T is a generic type constrained to any array or tuple type (specifically, any type that is assignable to readonly any[]). Intuitively, a variadic element ...T is a placeholder that is replaced with one or more elements through generic type instantiation. Instantiation of a tuple type with a variadic element ...T depends on the type argument provided for T
https://github.com/microsoft/TypeScript/issues/5453
*/

type Foo<T extends unknown[]> = [string, ...T, number]

type T1 = Foo<[boolean]> // [string, boolean, number]
type T2 = Foo<[number, number]> // [string, number, number, number]
type T3 = Foo<[]> // [string, number]

function concat<T extends unknown[], U extends unknown[]>(
t: [...T],
u: [...U]
): [...T, ...U] {
return [...t, ...u]
}

const t1 = concat([1, 2], ["hello"]) // [ number, number, string]
const t2 = concat([true], t1) // [boolean, number, number, string]
143 changes: 77 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5136845

Please sign in to comment.