-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
小程序 typescript 构建问题 #2699
Comments
欢迎提交 Issue~ 如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏 如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。 Good luck and happy coding~ |
这个跟 babel 无关,是你的语法问题。简单来说就是像 TypeScript Deep Dive 推荐的一样: use 参考: |
@yuche 这个是泛型啊。。。 |
看 #1851 |
看了的啊。这个地方根本就不是 type cast。不是 所谓的 是泛型声明。
|
看了下你的 runkit 应该是 另外这个 ts的版本是由 |
const ts = require("typescript");
const str = `
const responseHandler = <Output>({ data }: Taro.request.Promised<any>): Output => {
if (data.success) {
return data.content;
} else {
}
};
`
ts.transpileModule(str, {
compilerOptions: { module: ts.ModuleKind.CommonJS, jsx: false, target: 'esnext', lib: ['esnext'] }
}).outputText 这样能拿到正常结果 这个问题应该可以通过在调用处进行文件的后缀判断来解决。 |
现在普通 .ts 文件应该也能这么写,但 .tsx 还是会受限。 |
* upstream/master: (166 commits) docs: fix doc error as issue NervJS#2543 (NervJS#2714) feat(components): 完善 Input, Button, Textarea, WebView, Swiper 组件的类型定义 (NervJS#2713) feat(taro-components): 更新 Video 组件的类型定义 chore(taro-components): CommonEventFunction 支持传入 e.detail 的类型 refactor(transformer): 测试环境也需要提醒无法使用 index 作为 key test(transformer): 增加使用 index 作为 key 的测试用例, NervJS#2706 feat(transformer): 支持 export * from * 语法, close NervJS#959 export v from 'mod' 会转换为两行代码: import v from 'mod' export { v } feat(transformer): 支持 do expression,close NervJS#2589 refactor(cli): 在 ts 模板中更换 eslint parser, close NervJS#2268 fix(taro-cli): 更新微信小程序插件模板 fix(transformer): 只有 props 为 key 时才进行 key 不得为 index 的警告 (NervJS#2705) chore(components): ci问题修复 refactor(transformer): 对头条小程序的循环 ref 进行特殊处理 chore(webpack-runner): 固定webpack-runner的依赖版本 feat(h5): h5支持PullDownRefresh系列api feat(components): h5内置PullDownRefresh组件 fix(taro-cli): 修复 taro init 插件模板 test(transformer): 增加 typescript 测试用例, NervJS#2699 refactor(transformer): 只有 .tsx 才保留 JSX 声明,NervJS#2699 fix(taro-tt): 修复字节跳动小程序循环 ref ... # Conflicts: # packages/taro-cli/templates/mobx/globaldts
问题描述
项目中使用 typescript 语法。编译不通过。
复现步骤
[或者可以直接贴源代码,能贴文字就不要截图]
期望行为
正常编译不报错
报错信息
系统信息
另外本地的 typescript 版本为
3.4.2
。vscode 下此段代码无错误补充信息
大概是因为 Babylon 的 typescript 插件在 transform 的时候出现了问题。导致后续编译不通过。
目前改成这样写法绕过了:
感觉有 2 个解决方案
The text was updated successfully, but these errors were encountered: