Git Product home page Git Product logo

Comments (11)

blakeembrey avatar blakeembrey commented on May 22, 2024

What TypeScript version are you using it with? Can you post a reproducible test case?

That's a JavaScript error, so I think you're using this with a JavaScript file instead of a TypeScript file. Can you confirm that? Otherwise, I'd say it's the target output in tsconfig.json that's the issue (it's not supported with your node version).

from ts-node.

eggers avatar eggers commented on May 22, 2024

@blakeembrey This is a problem with my mocha tests. As per some instructions I found somewhere, I added require('ts-node/register') at the top of my gulpfile, and all of my typescript code/tests works nicely with a simple .pipe(mocha());. (Including ones with language features like async/away and yield.) However, if I use destructuring in my typescript code, then the tests will fail with the error above.

And, yes I'm using node 4.2.1 which doesn't support destructuring by default yet.

from ts-node.

blakeembrey avatar blakeembrey commented on May 22, 2024

Are the tests written in TypeScript or JavaScript. What about your tsconfig.json file - I guess you're targeting ES6? Is ts-node executing? I believe async/await and yield are all standard in node v4.

I'm not sure there's a solution if node doesn't support destructuring but does support things like async since TypeScript does not support as fine-grained tuning. If that's the case though, this is something to bring up with the TypeScript team (who I've seen discuss fine grained tuning in the past, so this just be an extra use-case on that).

from ts-node.

blakeembrey avatar blakeembrey commented on May 22, 2024

Following up quickly, check out https://kangax.github.io/compat-table/es6/#test-destructuring. Looks like this is an issue, TypeScript will only compile "all" ES6 for us but node can't handle destructuring (maybe other things).

from ts-node.

eggers avatar eggers commented on May 22, 2024

My tests are written in typescript. As far as I can tell, ts-node/register must be doing some kind of es5 transpilation because I'm pretty sure that node 4.2.1 doesn't support es6 imports yet (I also don't think that it supports async/await yet see: https://nodejs.org/en/docs/es6/), and I'm using those in my code & in my tests.

By the way, thanks for your work on the typings module, it's been a better solution that tsd for me so far.

from ts-node.

blakeembrey avatar blakeembrey commented on May 22, 2024

My tests are written in typescript

You're right, I had to investigate and found that node currently doesn't support destructuring. I wish there wasn't something we could do here since that's a trivial issue for the compiler to handle, but TypeScript doesn't support feature flags. An existing discussion can be found at microsoft/TypeScript#4692, but it looks like it might have been derailed - I'll check in and see what's happening since this is a pretty helpful use-case.

By the way, thanks for your work on the typings module

Thanks so much! I'm glad it works for you, I haven't had a lot of feedback yet so it's hard to tell if I'm confusing people or if it's communicating the message correctly. There's a need for more corrected typings, so if you get a chance 😄

from ts-node.

eggers avatar eggers commented on May 22, 2024

Yeah, I want to add some more typings because I'm having to install a lot of definitelytyped .d.ts files as ambient dependencies when I really want to save them as dev dependencies (a dev-ambient dependency might also help for things like mocha). I just want to get a better handle on it before I start making any pull requests. If you have, or were to make, a simple wiki page on how to create a typing definition project, I'd definitely start converting them.

I remember having a discussion when definitelytyped first came out that it would be better to have had each typing as a separate repo, but that met with a lot of resistance, so I'm really glad that you went in that direction...especially with the 1,385 folders that definitelytyped now handles.

from ts-node.

blakeembrey avatar blakeembrey commented on May 22, 2024

a dev-ambient dependency might also help for things like mocha

Haha, yeah, you're probably correct. I originally had that parity, but removed it from typings before release. I can simply add it back, ambient dependencies aren't included with any installation anyway - they are just for environment "reference" here.

If you have, or were to make, a simple wiki page on how to create a typing definition project

I'll look at adding one for you (or to the FAQ in the README), but it's mostly straightforward - just moving everything inside the ambient declare module "x" to outside and creating a repo for it. There's a lot in https://github.com/typings, though I wrote most of them from scratch. If you ever hit an issue, you can always open a discussion.

You can always create the files/repos under your own user too, then just add them to the registry 😄 Supporting DefinitelyTyped as ambient is a nice use-case too, which I've avoided documenting but perhaps I should if people are discovering it anyway. It would probably solve all the TSD woes.

from ts-node.

blakeembrey avatar blakeembrey commented on May 22, 2024

I'm going to reopen this for visibility or until it's fixed upstream in TypeScript

from ts-node.

frankwallis avatar frankwallis commented on May 22, 2024

FYI - If you are using mocha you can enable destructuring and default parameters using

mocha --harmony --harmony-destructuring --harmony_default_parameters

from ts-node.

blakeembrey avatar blakeembrey commented on May 22, 2024

Closing as answered, as far as I can tell it won't ever be fixed in TypeScript. Thankfully, ES6 works with node 6.

from ts-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.