rxjs: switchMap and switchMapTo

 https://stackoverflow.com/questions/39108549/switchmapto-creates-observable-before-subscription

It is calling early because you are calling the function when you are building the stream.


switchMap takes a function which gets invoked when a new value comes from up stream. The result of that function is subscribed to as a new stream.


switchMapTo takes an Observable which is subscribed to for every value that comes from up stream. You are creating the Observable by invoking getTestStartTime$().


Use switchMap when the output depends on the value coming from upstream, and use switchMapTo when the actual upstream value is irrelevant and is only used as a signal for subscription.


Getting To Know The Partial Type in TypeScript

 https://netbasal.com/getting-to-know-the-partial-type-in-typescript-ecfcfbc87cb6

I don’t usually bother to write about such small things, but I’ve come across many people who don’t know this handy feature, so I decided I should.

Let’s say we have a UserModel interface:

interface UserModel {
email: string;
password: string;
address: string;
phone: string;
}

And a User class with update() method:

class User {
update( user: UserModel ) {
// Update user
}
}

The problem with the code above is that we must pass an object that implements the whole UserModel interface, otherwise typescript will be 😡.

But in our case, we want to be dynamic and not be committed to the entire interface, but still get IntelliSense.

TypeScript (v2.1) provides us with a solution precisely for these cases — The Partial interface. All we need to do is to change the code above to this:

class User {
update( user: Partial<UserModel> ) {
// Update user
}
}

Now we can have the best of both worlds.

Another useful example would be if you have a component that takes configuration object as Input() and you want to have a default value.

type ComponentConfig = {
optionOne: string;
optionTwo: string;
optionThree: string;
}
export class SomeComponent { private _defaultConfig: Partial<ComponentConfig> = {
optionOne: '...'
}
@Input() config: ComponentConfig;

ngOnInit() {
const merged = { ...this._defaultConfig, ...this.config };
}
}

Under the hood the Partial interface looks like this:

type Partial<T> = { [P in keyof T]?: T[P]; };

You can read more about the keyof feature here.

https://stackoverflow.com/questions/54986332/typescript-class-extending-partial-interface


The problem is that Partial<T> will only allow you to implement the members will not require you to do so, and if you don't implement the member it will not be in the class.

You can create a function that returns a class and this class will implement the interface. The returned class will not actually have to declare any of the fields so they will all be undefined but this should be fine since the fields have to be optional anyway.

interface Animal {
    name: string;
}

type OptionalAnimal = Partial<Animal>;
function autoImplement<T>(): new () => T {
    return class { } as any;
}
class Dog extends autoImplement<OptionalAnimal>() {
    public constructor() {
        super();
    }
    public breed: string;
}

var spot = new Dog();

spot.name = "Spot"; // ok now

You can also cast the Dog class to specify that the returned instance has the members of Animal but these new members will not be accessible from inside the class:

interface Animal {
    name: string;
}

class _Dog {
    public constructor() {

    }
    public breed: string;
}

const Dog = _Dog as { new(): _Dog & Partial<Animal> } & typeof _Dog
type Dog = InstanceType<typeof Dog>

var spot = new Dog();

spot.name = "Spot"; 

How To Rename a Local and Remote Git Branch

 Source: https://linuxize.com/post/how-to-rename-local-and-remote-git-branch/


You are collaborating on a project with a group of people, and you have defined a naming convention for git branches. You created a new branch , pushed the changes to the remote repository, and realized that your branch name was incorrect.

Luckily, Git allows you to rename the branch very easily using the git branch -m command.

This guide explains how to rename local and remote Git branches.

Renaming Git Branch

Follow the steps below to rename a Local and Remote Git Branch:

  1. Start by switching to the local branch which you want to rename:

    git checkout <old_name>
  2. Rename the local branch by typing:

    git branch -m <new_name>

    At this point, you have renamed the local branch.

    If you’ve already pushed the <old_name> branch to the remote repository , perform the next steps to rename the remote branch.

  3. Push the <new_name> local branch and reset the upstream branch:

    git push origin -u <new_name>
  4. Delete the <old_name> remote branch:

    git push origin --delete <old_name>

That’s it. You have successfully renamed the local and remote Git branch

`npm build` doesn't run the script named “build” in package.json

 Source: https://stackoverflow.com/questions/29939697/npm-build-doesnt-run-the-script-named-build-in-package-json


Unfortunately npm build is already an internal command, as described in the docs:

This is the plumbing command called by npm link and npm install. It should generally not be called directly.

Because that command already exists, it always shadows over your "build": "node build.js".

The fully-qualified way to run your own script is with run-script or its alias run:

$ npm run build

npm start and others are the short-hand way, but is only an option when an existing npm command doesn't shadow it, like npm build does.


For posterity (as others have mentioned) npm build is used by npm to build native C/C++ Node addons using node-gyp. It's not documented well because usually it happens automatically, but if you're interested the source code is here.

Is it okay to use both fetchpriority="high" and loading="eager" in img tag?

 https://stackoverflow.com/questions/77744344/is-it-okay-to-use-both-fetchpriority-high-and-loading-eager-in-img-tag Yes Fetchpriority and l...