typescript

Run Nodemon with Typescript compiling?

可紊 提交于 2021-02-20 19:27:30
问题 I want my typescript files to be compiled on every file saving with the command tsc . How do I combine the tsc command with the command that nodemon runs in the build:live script "scripts": { "start": "npm run build:live", "build:live": "nodemon --watch '*.ts' --exec 'ts-node' app.ts", } this script causes nodemon to call itself twice or three times: "build:live": "nodemon --watch '*.ts' --exec 'ts-node app.ts & tsc'", 回答1: This looks like it will achieve what you're looking for: "start":

How to validate array length with io-ts?

杀马特。学长 韩版系。学妹 提交于 2021-02-20 19:26:27
问题 I am working on an io-ts validation where I would like to validate the list length (it has to be between min and max). I am wondering if there's a way to achieve this behavior since it could come quite handy at runtime for API endpoint validation. What I have so far is interface IMinMaxArray { readonly minMaxArray: unique symbol // use `unique symbol` here to ensure uniqueness across modules / packages } const minMaxArray = (min: number, max: number) => t.brand( t.array, (n: Array): n is t

Collapsing a discriminated union - derive an umbrella type with all possible key-value combinations from the union

北城以北 提交于 2021-02-20 19:23:52
问题 I have a discriminated union, for example: type Union = { a: "foo", b: string, c: number } | {a: "bar", b: boolean } I need to derive a type that includes all potential properties, assigned with types that may be found on any member of Union , even if only defined on some - in my example: type CollapsedUnion = { a: "foo" | "bar", b: string | boolean, c: number | undefined } How can I make a generic that derives such collapsed unions? I need a generic that supports unions of any size. Similar

Collapsing a discriminated union - derive an umbrella type with all possible key-value combinations from the union

﹥>﹥吖頭↗ 提交于 2021-02-20 19:23:07
问题 I have a discriminated union, for example: type Union = { a: "foo", b: string, c: number } | {a: "bar", b: boolean } I need to derive a type that includes all potential properties, assigned with types that may be found on any member of Union , even if only defined on some - in my example: type CollapsedUnion = { a: "foo" | "bar", b: string | boolean, c: number | undefined } How can I make a generic that derives such collapsed unions? I need a generic that supports unions of any size. Similar

Using generic type parameter as parameter

眉间皱痕 提交于 2021-02-20 19:10:58
问题 I'm trying to create a generic function which calls another function with an any type parameter. This is what I tried: static GetInstance<T>(): T { return <T>injector.get(T); // get(param: any): any } The problem is this doesn't compile. I'm getting Cannot find name 'T' error. I tried get(typeof T) but typeof T is string "function" . What can I do? For clarification: get() method accept types. For example you can use it like this: import { MyService } from '..' constructor(){ let val = this

Using generic type parameter as parameter

家住魔仙堡 提交于 2021-02-20 19:10:35
问题 I'm trying to create a generic function which calls another function with an any type parameter. This is what I tried: static GetInstance<T>(): T { return <T>injector.get(T); // get(param: any): any } The problem is this doesn't compile. I'm getting Cannot find name 'T' error. I tried get(typeof T) but typeof T is string "function" . What can I do? For clarification: get() method accept types. For example you can use it like this: import { MyService } from '..' constructor(){ let val = this

Using generic type parameter as parameter

南楼画角 提交于 2021-02-20 19:08:20
问题 I'm trying to create a generic function which calls another function with an any type parameter. This is what I tried: static GetInstance<T>(): T { return <T>injector.get(T); // get(param: any): any } The problem is this doesn't compile. I'm getting Cannot find name 'T' error. I tried get(typeof T) but typeof T is string "function" . What can I do? For clarification: get() method accept types. For example you can use it like this: import { MyService } from '..' constructor(){ let val = this

Typescript/babel import causing “_1.default is not a function”

心已入冬 提交于 2021-02-20 18:46:58
问题 I am trying to use https://github.com/timmywil/panzoom from a typescript project compiled with webpack and babel. The problem is that the typescript method call: import Panzoom from '@panzoom/panzoom'; Panzoom(document.querySelector("#pic")); is transpiled to the following javascript: panzoom_1.default(document.querySelector("#pic")); which then generates the following run-time error: Uncaught TypeError: panzoom_1.default is not a function If I debug the javascript then panzoom_1 has the

Typescript/babel import causing “_1.default is not a function”

旧巷老猫 提交于 2021-02-20 18:46:55
问题 I am trying to use https://github.com/timmywil/panzoom from a typescript project compiled with webpack and babel. The problem is that the typescript method call: import Panzoom from '@panzoom/panzoom'; Panzoom(document.querySelector("#pic")); is transpiled to the following javascript: panzoom_1.default(document.querySelector("#pic")); which then generates the following run-time error: Uncaught TypeError: panzoom_1.default is not a function If I debug the javascript then panzoom_1 has the

How to apply some style to the table row in angular material table

喜你入骨 提交于 2021-02-20 16:32:26
问题 I have this table : <div class="table-container"> <table mat-table [dataSource]="dataSource"> <mat-divider></mat-divider> <!-- title column --> <ng-container matColumnDef="title"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.NOTIFY_TITLE' | translate }} </th> <td mat-cell *matCellDef="let element"> {{element.title}} </td> </ng-container> <!-- code column --> <ng-container matColumnDef="description"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.DESCRIPTION' | translate }}