How to ‘map’ a Tuple to another Tuple type in Typescript 3.0

You’ll need to use a mapped tuple type, which is supported in TypeScript 3.1. You can make a mapped type that has properties 0, 1, 2 and length of the correct types, like this: class Maybe<T> {} type MaybeTuple = [Maybe<string>, Maybe<number>, Maybe<boolean>]; type MaybeType<T> = T extends Maybe<infer MaybeType> ? MaybeType : never; type … Read more

Do I ever need explicit allowSyntheticDefaultImports if esModuleInterop is true configuring TypeScript transpilation?

If you mean can you leave allowSyntheticDefaultImports undefined and define only esModuleInterop, the answer should be YES moving forward, but there has been an issue with this. PR #26866 seems to be a fix, only merged September 17, so it there may be some risk in the short term. As why both exist, I believe … Read more

Typescript 3 Angular 7 StopPropagation and PreventDefault not working

You have two different events, one is mousedown and another is click. The e.stopPropagation() only works if both of the events are of the same kind. You can change the input like this to work as expected: <input #inputBox matInput (click)=”fireEvent($event)” max-width=”12″ /> Live example: https://stackblitz.com/edit/angular-material-basic-stack-55598740?file=app/input-overview-example.ts

vscode typescript: ‘Add all missing imports’ shortcut

Is there a shortcut for the same? Yes, coming in v1.46 (see v1.46 release notes: add missing imports source action): Add all missing imports source action VS Code has long supported a quick fix that adds all missing imports in a JavaScript or TypeScript file. This iteration, we introduced a new Add all missing imports … Read more

How to define string literal union type from constants in Typescript

To get the type of a variable you need to use the typeof type operator: const MY_CONSTANT = ‘MY_CONSTANT’ // must be const, no annotation. let or var will not work const SOMETHING_ELSE = ‘SOMETHING_ELSE’ // must be const, no annotation. let or var will not work type MyType = typeof MY_CONSTANT | typeof SOMETHING_ELSE … Read more

‘unknown’ vs. ‘any’

You can read more about unknown in the PR or the RC announcement, but the gist of it is: [..] unknown which is the type-safe counterpart of any. Anything is assignable to unknown, but unknown isn’t assignable to anything but itself and any without a type assertion or a control flow based narrowing. Likewise, no … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)