typed-ember / ember-cli-typescript

Use TypeScript in your Ember.js apps!
https://docs.ember-cli-typescript.com
MIT License
363 stars 99 forks source link

ember-cli-typescript@2.0.0-beta.3 Gives typescript errors when using generics with arrow functions #398

Closed cptran777 closed 5 years ago

cptran777 commented 5 years ago

Please paste the output of ember -v here

ember-cli: 3.4.3 node: 8.11.3 os: darwin x64

Please paste the output of tsc -v here

Version 2.8.3

Please paste your tconfig.json and tslint.json or eslint.json (if applicable) below

My tsconfig.json
{
  "compilerOptions": {
    "target": "es2017",
    "allowJs": true,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": true,
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noEmitOnError": false,
    "noEmit": true,
    "inlineSourceMap": true,
    "inlineSources": true,
    "baseUrl": ".",
    "module": "es6",
    "paths": { "my-sandbox/tests/*": ["tests/*"],
      "my-sandbox/mirage/*": ["mirage/*"],
      "my-sandbox/*": ["app/*"],
      "*": ["types/*"]
    }
  },
  "include": ["app/**/*", "tests/**/*", "types/**/*", "mirage/**/*"]
}
My tslint.json or eslint.json

  

What are instructions we can follow to reproduce the issue?

git clone https://github.com/cptran777/ember-yarn-workspace-sandbox.git
yarn install
ember build

Now about that bug. What did you expect to see?

ember build should succeed.

What happened instead?

Typescript throws an error for some basic typescript type annotations. Example:

/Experiments/yarnworkspaces/ember-yarn-workspace-sandbox/packages/my-sandbox/my-sandbox/utils/api/error.ts: Unexpected token, expected ";" (51:53)

  49 |  * @returns {Promise<T>}
  50 |  */
> 51 | const throwIfApiError = async <T>(response: Response): Promise<T> => {
     |                                                      ^
  52 |   const { status, ok } = response;
  53 | 
  54 |   if (!ok) {

This not only happens on my newly created sandbox but on the code for a project I'm working on as well. Another example of an error:

/wherehows-web/utils/api/datasets/properties.ts: Unexpected token, expected ";" (40:39)

  38 |  * @returns {IDatasetPropertiesGetResponse | IDatasetPinotPropertiesGetResponse}
  39 |  */
> 40 | const readDatasetProperties = async <T extends IDatasetPropertiesGetResponse | IDatasetPinotPropertiesGetResponse>(
     |                                        ^
  41 |   id: number
  42 | ): Promise<IDatasetProperties> => {
  43 |   const { status, properties, message } = await getJSON<T>({ url: datasetPropertiesUrlById(id) });

These errors were fixed by returning to ember-cli-typescript@1.5.0. Looks like the issue might be for using generics and arrow functions, but I'm not 100% sure yet.

dfreeman commented 5 years ago

Hi @cptran777β€”thanks for testing out the 2.0 beta! I'm not able to reproduce the issue you're describing locally, and the repo you linked to looks like it only has a README and a .gitignore file in it. Maybe you forgot to push the reproduction code?

cptran777 commented 5 years ago

Hey @dfreeman , thanks for the response! And woops, the code is there now. New instructions for reproduction are

git clone https://github.com/cptran777/ember-yarn-workspace-sandbox.git
yarn install
cd packages/my-sandbox
ember build
dfreeman commented 5 years ago

@cptran777 Other than a Sass issue that I assume is unrelated, everything seemed to build correctly for me when I cloned that repo πŸ€”

$ git clone git@github.com:cptran777/ember-yarn-workspace-sandbox.git
Cloning into 'ember-yarn-workspace-sandbox'...
remote: Enumerating objects: 86, done.
remote: Counting objects: 100% (86/86), done.
remote: Compressing objects: 100% (60/60), done.
remote: Total 86 (delta 8), reused 82 (delta 7), pack-reused 0
Receiving objects: 100% (86/86), 191.40 KiB | 0 bytes/s, done.
Resolving deltas: 100% (8/8), done.

$ cd ember-yarn-workspace-sandbox

$ yarn
yarn install v1.12.3
[1/4] πŸ”  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] πŸ”—  Linking dependencies...
warning "ember-cli-typescript > @babel/plugin-proposal-class-properties@7.1.0" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "ember-cli-typescript > @babel/plugin-transform-typescript@7.1.0" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "ember-cli-typescript > @babel/plugin-proposal-class-properties > @babel/plugin-syntax-class-properties@7.0.0" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "ember-cli-typescript > @babel/plugin-transform-typescript > @babel/plugin-syntax-typescript@7.1.5" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "workspace-aggregator-758f57bd-c446-4846-82b7-4a75e21bb1bf > some-addon > eslint-plugin-node@7.0.1" has unmet peer dependency "eslint@>=4.19.1".
warning "workspace-aggregator-758f57bd-c446-4846-82b7-4a75e21bb1bf > my-sandbox > @ember-decorators/babel-transforms > @babel/plugin-proposal-decorators@7.1.2" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "workspace-aggregator-758f57bd-c446-4846-82b7-4a75e21bb1bf > some-addon > eslint-plugin-node > eslint-plugin-es@1.3.2" has unmet peer dependency "eslint@>=4.19.1".
warning "workspace-aggregator-758f57bd-c446-4846-82b7-4a75e21bb1bf > my-sandbox > @ember-decorators/babel-transforms > @babel/plugin-proposal-decorators > @babel/plugin-syntax-decorators@7.1.0" has unmet peer dependency "@babel/core@^7.0.0-0".
[4/4] πŸ“ƒ  Building fresh packages...
✨  Done in 25.21s.

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean

$ cd packages/my-sandbox

$ ember build
Environment: development
cleaning up...
Build Error (SassCompiler)

File not found: /app/styles/app.scss
in any of the following include paths:
  /Users/dfreeman/Desktop/Scratch Code/ember-yarn-workspace-sandbox/packages/my-sandbox/tmp/sass_compiler-input_base_path-SXnxJvFZ.tmp

Stack Trace and Error Report: /var/folders/5m/q_433rys3rjb60zs14zd88nc0000gn/T/error.dump.5d25a3580382f5ca4cf32846b98ff464.log

$ mv app/styles/app.{css,scss}

$ ember build
Environment: development
cleaning up...
Built project successfully. Stored in "dist/".
cptran777 commented 5 years ago

Woops! Sorry, so the code I checked in included the "fix" which was changing from arrow function to a regular function, which I was doing to test my theory about the arrow function being the issue. Just added a commit to revert that change.

cptran777 commented 5 years ago

@dfreeman ^

dfreeman commented 5 years ago

Aha, got it. It looks like you're running into https://github.com/babel/babel/issues/9006 @cptran777

chriskrycho commented 5 years ago

@cptran777 would you mind pull the latest release candidate (ember install ember-cli-typescript@next) and confirm that you don't see this issue any more? The upstream issue has been fixed and we're up to date on our Babel dependency, so I think it should be resolved now!

chriskrycho commented 5 years ago

This was fixed upstream. πŸŽ‰