tsc

Declare dynamically added class properties in TypeScript

给你一囗甜甜゛ 提交于 2019-11-29 07:06:14
I want to assign properties to the instance of a class without knowing the property names, values and types of values in TypeScript. Lets assume we have the following example.ts script: // This could be a server response and could look totally diffent another time... const someJson:string = '{ "foo": "bar", "bar": "baz" }' class MyClass { someProperty:boolean constructor( json:string ) { const parsedJson:any = JSON.parse( json ) Object.keys( parsedJson ).forEach( ( key:string ) => { this[ key ] = parsedJson[ key ] } ) this['someProperty'] = true } } const myInstance = new MyClass( someJson ) /

Typescript build getting errors from node_modules folder

三世轮回 提交于 2019-11-29 01:45:49
I am running a typescript build and getting errors in node_modules. Why isn't it ignoring this folder? I have it in the exclude section of my tsconfig.json. The really strange thing is that I have another project that I have done a file comparison with and it does not throw these errors even though gulpfile.js, tsconfig.json and the node_modules folders are identical. What else can I check? Errors: c:/Dev/streak-maker/node_modules/angular2/src/core/change_detection/parser/locals.d.ts(3,14): error TS2304: Cannot find name 'Map'. c:/Dev/streak-maker/node_modules/angular2/src/core/change

Is there a way to use npm scripts to run tsc -watch && nodemon --watch?

妖精的绣舞 提交于 2019-11-28 19:48:08
问题 I'm looking for a way to use npm scripts to run tsc --watch && nodemon --watch at the same time. I can run this commands independently, but when I want run both of them, only the first one is executed. eg. if I have this script: "scripts": { "runDeb": "set NODE_ENV=development&& tsc --watch && nodemon --watch" } tsc --watch is executed but nodemon is never called, and vice versa. 回答1: I think what you want is something like this (my current setup): "scripts": { "compile": "tsc && node app.js"

'Cannot redeclare block-scoped variable' in unrelated files

这一生的挚爱 提交于 2019-11-27 17:57:49
There is a simple TS package that is used as CommonJS modules and has no exports. TS files are compiled to JS files with the same name and used as require('package/option-foo') . tsconfig.json: { "compilerOptions": { "target": "es5" } } option-foo.ts: declare const GlobalVar: any; function baz() {} if (GlobalVar.foo) GlobalVar.baz = baz; option-bar.ts: declare const GlobalVar: any; function baz() {} if (GlobalVar.bar) GlobalVar.baz = baz; The important part here is that option-foo and option-bar are never used together . There are other complimentary TS files in the project, but they don't

TypeScript - How to keep compiled files in a separate directory?

有些话、适合烂在心里 提交于 2019-11-27 17:55:27
I'm fairly new to TypeScript, and right now I have .ts files in several places throughought my project structure: app/ |-scripts/ |-app.ts | |-classes/ | |-classA.ts | |-classB.ts | |-controllers/ | |-controllerA.ts | |-controllerB.ts | |-otherStuff/ |-otherstuffA.ts Right now, when my files are compiled, they are compiled to the same directory that the .ts fles are in: app/ |-scripts/ |-app.ts |-app.js | |-classes/ | |-classA.ts | |-classB.ts | |-classA.js | |-classB.js | |-controllers/ | |-controllerA.ts | |-controllerB.ts | |-controllerA.js | |-controllerB.js | |-otherStuff/ |-otherstuffA

Typescript build getting errors from node_modules folder

浪子不回头ぞ 提交于 2019-11-27 16:06:03
问题 I am running a typescript build and getting errors in node_modules. Why isn't it ignoring this folder? I have it in the exclude section of my tsconfig.json. The really strange thing is that I have another project that I have done a file comparison with and it does not throw these errors even though gulpfile.js, tsconfig.json and the node_modules folders are identical. What else can I check? Errors: c:/Dev/streak-maker/node_modules/angular2/src/core/change_detection/parser/locals.d.ts(3,14):

Typescript primitive types: any difference between the types “number” and “Number” (is TSC case-insensitive)?

﹥>﹥吖頭↗ 提交于 2019-11-27 12:58:09
I meant to write a parameter of type number , but I misspelled the type, writing Number instead. On my IDE (JetBrains WebStorm) the type Number is written with the same color that is used for the primitive type number , while if I write a name of a class (known or unknown) it uses a different color, so I guess that somehow it recognizes the misspelled type as a correct/almost-correct/sort-of-correct type. When I compile the code, instead of complaining for example that the compiler couldn't found a class named Number , TSC writes this error message: Illegal property access Does that mean that

How can I pass multiple source files to the TypeScript compiler?

*爱你&永不变心* 提交于 2019-11-27 12:43:45
问题 TypeScript is designed for large-scale JavaScripty projects which typically consist of multiple internally produced files along with externally produced libraries. How does the TypeScript compiler (tsc) expect you to provide it with the complete set of files that make up a project? 回答1: dir *.ts /b /s > ts-files.txt tsc @ts-files.txt del ts-files.txt This will compile all *.ts files in working directory and its sub directories. If you don't want to include sub directories, just remove the /s

How to consume npm modules from typescript?

大城市里の小女人 提交于 2019-11-27 06:43:11
I'm giving a shot at typescript. It works fine at the hello world stage. I'm now trying to use a npm module : index.ts = import _ = require('lodash') console.log(_.toUpper('Hello, world !')) This doesn't work : tsc index.ts -> Cannot find module 'lodash'. (2307) node-ts index.js -> Cannot find module 'lodash'. (2307) Looking at typescript documentation and in google didn't help. Other S/O questions are either unanswered ( here and here ) or unrelated. Elements : typescript 1.8 latest Yes, lodash is installed npm i --save lodash and exists in my filesystem (checked) I also did typings i --save

Memory latency measurement with time stamp counter

前提是你 提交于 2019-11-26 22:25:51
问题 I have written the following code which first flushes two array elements and then tries to read elements in order to measure the hit/miss latencies. #include <stdio.h> #include <stdint.h> #include <x86intrin.h> #include <time.h> int main() { /* create array */ int array[ 100 ]; int i; for ( i = 0; i < 100; i++ ) array[ i ] = i; // bring array to the cache uint64_t t1, t2, ov, diff1, diff2, diff3; /* flush the first cache line */ _mm_lfence(); _mm_clflush( &array[ 30 ] ); _mm_clflush( &array[