typescript2.2

Publishing Typescript 2.3 Modules to NPM for Angular 4 Consumption

微笑、不失礼 提交于 2020-01-02 07:45:12
问题 There are related instructions in Writing NPM modules in Typescript , however it's dated and there are now a lot of different answers which may or may not work for Angular. There's also a very good presentation by Jason Aden on youtube on how to publish Angular Components, but in this case I'm only interested in publishing vanilla typescript classes. 回答1: I finished a prototype for testing this out. I used code from this article - creating npm modules written in typescript and the rollup

Is it possible to pass Typescript decorator object values in at runtime?

一世执手 提交于 2019-12-13 21:56:01
问题 I have a class that is decorated with a @MinDate constraint like this: export default class Order { purchaseDate: Date; @MinDate(this.purchaseDate) receiptDate: Date; } When attempting to validate an instance of Order that is valid the validation errors out. My question is is it even possible / valid to pass in this.purchaseDate as an argument to the @MinDate() decorator. In other words can typescript decorators receive runtime values from an object, or do these values have to be available at

Should the typescript lib setting dom be included when developing an angular 4 component?

半世苍凉 提交于 2019-12-12 04:47:16
问题 In this article on distributing an angular library the author says that it's a good idea to not touch the dom directly because it makes the component unusable inside web workers. Should we thus leave dom out of the typescript lib compiler option or are there certain use cases where we absolutely need it? Here's an example with dom included: "compilerOptions": { "target": "es5", "module": "es2015", "lib": ["es2015", "dom"] }, The sample tsconfig.json compiler options includes dom ... 回答1: It

Typescript 2 wildcard module

早过忘川 提交于 2019-12-11 06:34:18
问题 I am having trouble with importing html templates in my angular 2 app. In globals.d.ts declare module "*.html" { const content: string; export default content; } In app.component.ts import { Component } from '@angular/core'; import './app.component.css'; import * as template from './app.component.html'; @Component({ selector: 'app', template: <string>template }) export class AppComponent { constructor() { console.log('I am App'); } } The app works and the template is loaded but I get this

Import module from root path in TypeScript

江枫思渺然 提交于 2019-12-08 15:40:36
问题 Let's suppose I've a project, and its main source directory is: C:\product\src Based on this directory, every import path would be relative to it. I.e., suppose: // Current script: C:\product\src\com\name\product\blah.ts import { thing } from '/com/name/product/thing'; same as: // Current script: C:\product\src\com\name\product\blah.ts import { thing } from '../../../com/name/product/thing'; My entry compilation file would be at: C:\product\src for instance. So, is there a way to specify this