-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typscript async/await not working #3274
Comments
does async/await work normally with typescript? I'm not super familiar with it, perhasp you need to set the right config options? |
@jquense should be supported from v. 1.7 https://blogs.msdn.microsoft.com/typescript/2015/11/03/what-about-asyncawait/ I'm using typescript v. 2.6.1 |
Hmmm it could be related to this? https://templecoding.com/blog/2016/02/17/async-await-with-es6-babel-and-typescript/ |
Can you add an example repo? Assume you are using https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-typescript? Can you try inserting await in https://github.com/gatsbyjs/gatsby/tree/master/examples/using-typescript and seeing if you can repro? |
@calcsam here's a repo demonstrating it https://github.com/wedelgaard/gatsby-typescript-starter |
Thanks for the repro! On that repo for me locally gatsby-build fails but gatsby-develop succeeds. Will label this as a bug, someone more familiar than me with TS syntax should probably take a look :) |
Can reproduce here too, same problem as #3356 I believe. TL;DR: TS is set to transpileOnly by default, which means it will check the types and return the source file sans TS semantics. Given that there's no babel pipeline to process it further the other code is effectively dealing with esnext and chokes up on it. That said, |
I don't understand why target exnext is forced here? gatsby/packages/gatsby-plugin-typescript/src/gatsby-node.js Lines 38 to 42 in ab1d7f5
if the typescript plugin allows specifying target from outside we can resolve this issue by specifying a lower level target like es5 in tsconfig |
I believe the tagged literals appeared only in es2015, so you can go down at most to es2015. It doesn't make much sense as babel is supposed to handle es2015..esnext difference too, though. |
Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help! |
It seems like async/await it not working when using gatsby-plugin-typescript :( The following error is thrown:
{my path}/gatsby-site/src/pages/index.tsx Unexpected token (13:26) You may need an appropriate loader to handle this file type.
this is how the pages/index.tsx looks like. It works without any problems if index.tsx is renamed to index.js (not typescript), but this is not desirable.
`
import * as React from 'react'
import Link from 'gatsby-link'
const asyncFunc = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('done!')
}, 1000)
})
}
const getStuff = async () => {
return await asyncFunc()
}
const IndexPage = (props: any) => {
const test = getStuff()
return (
...something
)
}
export default IndexPage
`
The text was updated successfully, but these errors were encountered: