typescript3.0

Preventing inappropriate imports and enforcing project hierarchy in Typescript

妖精的绣舞 提交于 2020-05-14 19:47:50
问题 In a TS project I'd like the following to be blocked: A file from folder common importing from folder projectA A file from folder projectB importing from folder projectA I'd like the following to be allowed: A file from folder projectA importing from folder projectA A file from folder projectA importing from folder common. I'm aware of References. However, as I understand, they require a build for type checking (If such a separation is made, one must build to create d.ts files first) which I

Typescript 3 Angular 7 StopPropagation and PreventDefault not working

纵然是瞬间 提交于 2020-05-11 03:55:45
问题 I have a text input inside a div. Clicking on the input should set it to focus and stop the bubbling of the div click event. I've tried the stopPropagation and preventDefault on the text input event but to no avail. The console logs shows that the div click still executes regardless. How to stop the div click event from executing? // html <div (click)="divClick()" > <mat-card mat-ripple> <mat-card-header> <mat-card-title> <div style="width: 100px"> <input #inputBox matInput (mousedown)=

Typescript 3 Angular 7 StopPropagation and PreventDefault not working

对着背影说爱祢 提交于 2020-05-11 03:55:30
问题 I have a text input inside a div. Clicking on the input should set it to focus and stop the bubbling of the div click event. I've tried the stopPropagation and preventDefault on the text input event but to no avail. The console logs shows that the div click still executes regardless. How to stop the div click event from executing? // html <div (click)="divClick()" > <mat-card mat-ripple> <mat-card-header> <mat-card-title> <div style="width: 100px"> <input #inputBox matInput (mousedown)=

How do you get the type of the object that is cloned from a Class Instance?

末鹿安然 提交于 2020-03-25 17:34:23
问题 The bounty expires in 2 days . Answers to this question are eligible for a +50 reputation bounty. lonewarrior556 wants to draw more attention to this question. assume I have this example class, but in reality it has many more properties class Foo { name: string dob: number constructor(name: string, dob: number) { this.name = name; this.dob = dob; } get age() { return new Date().getTime() - this.dob } } Now Typescript is smart and when I instantiate the class it will give me all the right

Extending built-in types in Typescript

不羁的心 提交于 2020-02-24 14:14:39
问题 I have the following structure: project |- types |- global.d.ts |- string.d.ts |- wdio.d.ts |- src |- Models |- Resources |- Components |- Extensions |- string.ts |- ... |- tsconfig.json |- wdio.conf.js I try to extend the string's prototype with a function. I tried so far a lot of way, I found on several sites. But either the tsc gives me error, or the PHPStorm shows error message. // types/string.d.ts declare interface String { myCustomFn(text : string) : string; } // src/Extensions/string

Extending built-in types in Typescript

匆匆过客 提交于 2020-02-24 14:11:47
问题 I have the following structure: project |- types |- global.d.ts |- string.d.ts |- wdio.d.ts |- src |- Models |- Resources |- Components |- Extensions |- string.ts |- ... |- tsconfig.json |- wdio.conf.js I try to extend the string's prototype with a function. I tried so far a lot of way, I found on several sites. But either the tsc gives me error, or the PHPStorm shows error message. // types/string.d.ts declare interface String { myCustomFn(text : string) : string; } // src/Extensions/string

Extending built-in types in Typescript

爱⌒轻易说出口 提交于 2020-02-24 14:10:48
问题 I have the following structure: project |- types |- global.d.ts |- string.d.ts |- wdio.d.ts |- src |- Models |- Resources |- Components |- Extensions |- string.ts |- ... |- tsconfig.json |- wdio.conf.js I try to extend the string's prototype with a function. I tried so far a lot of way, I found on several sites. But either the tsc gives me error, or the PHPStorm shows error message. // types/string.d.ts declare interface String { myCustomFn(text : string) : string; } // src/Extensions/string

“Cannot find module” error when using TypeScript 3 Project References

谁说我不能喝 提交于 2020-01-23 11:09:18
问题 I'm trying to get TypeScript 3's project references working but struggling to import a function from a referenced project. I have a ProjectA that references Shared . Here's the file structure: ProjectA |_ src | |_person.ts |_ tsconfig.json | Shared |_ src |_utils.ts |_ tsconfig.json Here's utils.ts : export function guid() { return "a guid"; } Here's Shared/tsconfig.json : { "compilerOptions": { "composite": true, "declaration": true, "target": "es5", "outDir": "dist", "module": "es6",

TypeScript const assertions: how to use Array.prototype.includes?

六月ゝ 毕业季﹏ 提交于 2020-01-20 08:39:27
问题 I am trying to use an array of elements as union type, something that became easy with const assertions in TS 3.4, so I can do this: const CAPITAL_LETTERS = ['A', 'B', 'C', ..., 'Z'] as const; type CapitalLetter = typeof CAPITAL_LETTERS[string]; Now I want to test whether a string is a capital letter, but the following fails with "not assignable to parameter of type": let str: string; ... CAPITAL_LETTERS.includes(str); Is there any better way to fix this rather than casting CAPITAL_LETTERS to

TypeScript const assertions: how to use Array.prototype.includes?

你。 提交于 2020-01-20 08:38:06
问题 I am trying to use an array of elements as union type, something that became easy with const assertions in TS 3.4, so I can do this: const CAPITAL_LETTERS = ['A', 'B', 'C', ..., 'Z'] as const; type CapitalLetter = typeof CAPITAL_LETTERS[string]; Now I want to test whether a string is a capital letter, but the following fails with "not assignable to parameter of type": let str: string; ... CAPITAL_LETTERS.includes(str); Is there any better way to fix this rather than casting CAPITAL_LETTERS to