teppeis / typescript-simple

Simple API to compile TypeScript code string to JavaScript. That's all!
80 stars 21 forks source link

Reference external modules #15

Open Maxim-Filimonov opened 9 years ago

Maxim-Filimonov commented 9 years ago

Is it possible to use this module to compile source code which is using external modules? I can't figure out how to make this simple file to work

/// <reference path="typings/tsd.d.ts"/>
import $ = require("jquery");

Keep getting

L1: File 'typings/tsd.d.ts' not found.
L2: Cannot find external module 'jquery'.
basarat commented 9 years ago

Disable semantic checks. It's an option.

Maxim-Filimonov commented 9 years ago

I'm looking at https://github.com/Microsoft/TypeScript/blob/v1.4/bin/typescriptServices.d.ts#L1086 Not sure which option

basarat commented 9 years ago

@Maxim-Filimonov sample : https://github.com/basarat/typescript-simple/commit/7503d1447606d13c8103d268ecc9242874ff750f#diff-c1129c8b045390789fa8ff62f2c6b4a9R81

doSemanticChecks : https://github.com/basarat/typescript-simple/commit/7503d1447606d13c8103d268ecc9242874ff750f#diff-ed009b6b86b017532ef0489c77de5100R30

teppeis commented 9 years ago

@Maxim-Filimonov I've added about doSemanticChecks to README!

teppeis commented 9 years ago

Resolving reference path in typescript-simple is not simple. Because typescript-simple doesn't know the path of source code, it cannot resolve the relative reference path. It requires another option.

Maxim-Filimonov commented 9 years ago

Yeah I'm not an expert but maybe this can be adopted somehow: https://github.com/ivogabe/gulp-typescript/blob/3422fbff06532ccc57368f3b4c8801de8f72ef27/lib/project.ts#L263 I feel like I am using typescript-simple for the case it's not supposed to be used:

I'm using jest test framework to test react components written in typescript. I'm trying to use typescript-simple to compile *.ts files into .js so that jest can require them. Is that a valid use case or not?

basarat commented 9 years ago

Is that a valid use case or not

Valid use case. Its used by atom to allow it to require .ts files https://github.com/atom/atom/pull/5898

basarat commented 9 years ago

gulp / grunt etc are great for complete validation of your code. Jest doesn't care.

teppeis commented 9 years ago

@Maxim-Filimonov

I'm trying to use typescript-simple to compile *.ts files into .js

typescript-simple doesn't compile multiple file structure, because of the simplicity. I think official tsc or other full-featured tool is better for your case.

blakeembrey commented 9 years ago

@teppeis @basarat I appear to be having the same issue. I just discovered that atom uses this module to transpile TypeScript (https://github.com/atom/atom/blob/a70be30ee7017b86114592800d9d4bdccff88aa8/src/typescript.coffee#L60-L62) but I get At L1: File '../../typings/tsd.d.ts' not found.

basarat commented 9 years ago

@blakeembrey can you share the src code that atom is trying to compile? You shouldn't be getting this error because we have semantic checks switched of new TypeScriptSimple(options, false) i.e. false in the second option

basarat commented 9 years ago

@blakeembrey I just did a quick test : this package works fine : https://github.com/basarat/atom-typescript-test/blob/master/index.ts#L1

blakeembrey commented 9 years ago

Ok, I'm trying to update now just in case (turns out I'm using Atom 0.190.0 but I didn't see any commits in between that changed things).

basarat commented 9 years ago

Hmm sorry. I just hit it

image

blakeembrey commented 9 years ago

@basarat That looks like it :+1: What did you do different? On that note, updating didn't change anything for me either.

basarat commented 9 years ago

What did you do different?

I did reload atom with ctrl+alt+r somehow that didn't capture it. Quiting and reopening atom triggered it

basarat commented 9 years ago

@teppeis Issue is that reference imports are considered a syntactic error.

basarat commented 9 years ago

@teppeis added failing test : https://github.com/teppeis/typescript-simple/pull/18

basarat commented 9 years ago

@blakeembrey note that the current workaround is not to use reference imports.

NOTE: reference imports should not be used and are not needed if you are using external modules with tsconfig.json : https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md

basarat commented 9 years ago

@teppeis We have a passing build + fix with TypeScript 1.5 : https://github.com/teppeis/typescript-simple/pull/19

teppeis commented 9 years ago

@basarat thanks! @blakeembrey sorry, please wait for TypeScript 1.5.

LiJinyao commented 7 years ago

This change broke the getScriptSnapshot behavior which lead to this issue https://github.com/power-assert-js/espower-typescript/issues/35