new Typescript “satisfies” operator

The difference is what you can do with favoriteColors after you define it. With satisfies, the actual type of the assigned object literal is used as the type of favoriteColors, the information about what keys and values it contains is preserved (the type of the object literal is just checked against the type it’s supposed … Read more

The typescript shows an error “Object is possibly ‘undefined'”

This is currently a limitation of TypeScript as described in microsoft/TypeScript#10530. You’re expecting that by checking feeObj[property] !== undefined that TypeScript will narrow the type of feeObj[property] from number | undefined to undefined, but unfortunately that isn’t happening. TypeScript does normally allow such equality narrowing on property accesses, as shown here: function works(feeObj: FeeObjType2) { … Read more

Why does a Typescript type conditional on `T extends undefined`, with T instantiated with `boolean`, resolve T to `never`?

As written, type OptionalArgBroken<Arg> = Arg extends undefined ? () => void : (arg: Arg) => void; is a distributive conditional type because the type being checked, Arg, is a naked generic type parameter. “Distributive” means that if the Arg passed in is a union, then the type will be evaluated for each member of … Read more

detect change of nested property for component input

In fact, by default Angular2 detects changes when object reference is updated not its content. But this default behavior can be changed by using the DoCheck interface. In your case (detecting that a property was updated into the myObject object, you could use the following approach: @Component({ selector: ‘my-component’, (…) }) export class MyComponent implements … Read more

Is it possible to narrow the types of overloaded parameters without exhaustively checking each parameter in the function body?

This is now possible to a limited extent with TypeScript 4.6’s Control Flow Analysis for Dependent Parameters. TypeScript can narrow down the types of arguments if the narrowing is done with ===. (A typeof check doesn’t appear to work, at least not yet.) To tweak the example in the question, if the first argument, when … Read more