tsc

TypeScript via tsc command: Output to single file without concatenation

﹥>﹥吖頭↗ 提交于 2020-01-03 07:29:23
问题 Is there a way of compiling single .ts file to different directory? The only way from the manual command of compilation to different directory is via --out command, but it also does concatenation of dependent files, which I don't want: --out FILE|DIRECTORY Concatenate and emit output to single file | Redirect output structure to the directory Is there a way of redirecting the output WITHOUT concatenation of input files? 回答1: Unfortunately it's impossible to compile multiple *.ts files into

Webpack with a client/server node setup?

狂风中的少年 提交于 2020-01-01 04:57:24
问题 I'm trying to set up a webpack-based flow for an Angular2 app with a node backend server. After many hours banging my head against it, I've managed to get the client to build happily, but I can not figure out how to now integrate my server build. My server uses generators, so must target ES6, and it needs to point to a different typings file (main.d.ts instead of browser.d.ts).. My source tree looks like; / -- client/ -- -- <all my angular2 bits> (*.ts) -- server/ -- -- <all my node/express

What's the difference between tsc (TypeScript compiler) and ts-node?

天大地大妈咪最大 提交于 2019-12-30 06:31:44
问题 I'm very confused about the difference between tsc and ts-node . I'm learning TypeScript and I usually transpile server .ts files with tsc command. Now, I'm approaching nestjs framework, and I see that it uses ts-node . So what's the difference between the two? Which one should I use? 回答1: The main difference is that tsc transpile all the file according to your tsconfig. Instead, ts-node will start from the entry file and transpile the file step by step through the tree based on the import

ts结合vue使用的感悟

China☆狼群 提交于 2019-12-30 03:53:39
TypeScript 前端现在越来越强大,多人开发更是常见,加上各大框架都开始支持TypeScript,而谷歌和微软又更加积极,导致不得不去学习,顺道通过js来了解ts,再通过ts来了解强类型语言。一路走来,辛酸二字不足形容,道行太浅,终究惨不忍睹。特在此记上一笔。以备将来继续踩坑前行。 TypeScript使用 官方文档 EN 2.9 | 中文 2.7 推荐使用使用英文文档,明显比中文更新更快 不知道算不算阮一峰的 这个过于简单了,但是归纳的挺好的 使用流程 全局安装 typescript 版本检测 tsc -v 新建文件后缀以 .ts 即可 ts ==> js 执行命令 tsc **.ts ==> **.js 随时更改,随时转 tsc **.ts -w 多个文件处理 需要配置 typescript.json ==> tsc init typescript.json 配置 files 到此基本可用 准备接入 vue 官方介绍 目前可以看来 vue 本意使用 flow ,奈何 typescript 已成大势所趋,不得不跟进脚步了 目前有两种方式 直接基于之前的vue进行修改即可 Microsoft 这种学习成本低,改起来快,但却没有很好地发挥其作用 基于 vue-cli.3.0 进行开发,这个学习成本大,很多东西不是很完善,而且相应的资料不完成,很痛苦 使用到官方维护插件 vue

Typescript “error TS2532: Object is possibly 'undefined'” even after undefined check

故事扮演 提交于 2019-12-29 08:27:16
问题 I'm trying to use the --strict option on tsc but I ran into the following "weird" case that I don't seem to understand. If I write: function testStrict(input: {query?: {[prop: string]: string}}) { if (input.query) { Object.keys(input.query).forEach(key => { input.query[key]; }) } return input; } the compiler complains about: test.ts(5,9): error TS2532: Object is possibly 'undefined'. (the offending line is input.query[key]; ) What I don't understand is, I have already checked for undefined

Building a class registry: Cannot use 'new' with an expression whose type lacks a call or construct signature

夙愿已清 提交于 2019-12-29 07:19:08
问题 I have this setup: //./things/Base.ts export default class Base{ constructor(){ console.log("HI I AM A BASE THING"); } } //things.ts import Base = require('./things/Base'); export = { defaultThing: Base }; //entry.ts import Things = require('./things'); new Things.defaultThing(); What I'm trying to do is build a dictionary with the keys I want for classes of a given type, letting me change the underlying implementation without touching the consuming code. This fails with the following message

TypeScript generating wrong JS in Release Mode

寵の児 提交于 2019-12-25 06:23:39
问题 I do not know if this is a known issue. I am working with VS 2012 Web Express with Typescript 0.8.1.1. I am using the --module AMD clause to generate AMD modules. Iin Debug mode the compiler generates a define clause like this: define(["require", "exports", "app/Config", "app/ModelLocator", "app/Presenter", "app/Messenger", "app/LogOnWindow", "app/vm/VmAppHeader", "app/framework/PageLocator", "app/framework/ViewStacks"], function(require, exports, __cfg__, __ml__, __pr__, __ms__, __rc__, __lw

tsc seemingly not picking up “exclude” options fro tsconfig.json

纵饮孤独 提交于 2019-12-23 13:07:10
问题 I am struggling to get tsc to pick up my tsconfig.json file and compile my .ts files. it runs into duplication errors which I am trying to avoid with my tsconfig.json. I have: package.json tsconfig.json typings.json typings / main/ ...etc browser/ ...etc main.d.ts browser.d.ts src / ... <source files in here.> My typings.json looks like: { "ambientDependencies": { "es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654", "jasmine": "registry:dt/jasmine#2.2.0+20160412134438", "node": "registry

Get type completion based on dynamic (mapped/conditional) type

女生的网名这么多〃 提交于 2019-12-23 05:26:58
问题 You can drop the following code into a foo.ts file. I am trying to dynamically generate types. What I am doing is based off this question: Map array to an interface type TypeMapping = { Boolean: boolean, String: string, Number: number, ArrayOfString: Array<string>, } export enum Type { Boolean = 'Boolean', String = 'String', Number = 'Number', ArrayOfString = 'ArrayOfString' } const asOptions = <K extends Array<string>, T extends Array<{ name: K, type: keyof TypeMapping }>>(t: T) => t; type

TypeScript compile and keep comments

牧云@^-^@ 提交于 2019-12-22 03:43:24
问题 I like to have my comments intact in the resulting javascript file, by default the compiler removes them. Is there a tsc parameter for that? (The use case is to keep /// reference path's = ... for chutzpah unit testing. ) 回答1: Yes, the -c (or --comments) option; Syntax: tsc [options] [file ..] Examples: tsc hello.ts tsc --out foo.js foo.ts tsc @args.txt Options: -c, --comments Emit comments to output ... 回答2: Comments that start with /*! are preserved. example: /*! this comment remains