Skip to content
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

ts 编译报错 #1498

Closed
youzipi opened this issue Dec 13, 2018 · 5 comments
Closed

ts 编译报错 #1498

youzipi opened this issue Dec 13, 2018 · 5 comments
Labels
question Further information is requested

Comments

@youzipi
Copy link

youzipi commented Dec 13, 2018

问题描述
使用 异步的 action。
之前在js下,是可以正常运行的。
改成 ts 后,编译报错。

复现步骤

image

// async actions
export const fetchCompany = () => {
  return async (dispatch) => {
    let {data} = await companyApi.buyerList()
    dispatch({
      type: SET_BUYER_LIST,
      companyList: data,
    })
  }
}
// buyerList 最底层的请求定义:
// utils/fetch.ts
const RequestHandler: (config: any) => Promise<any>

简化后,还是报错:

const test = () => {
  return (dispatch) => {
    let a = {b: 123}
    let {b} = a
    console.log(b)
  }
}

image

简化成这样还是报错:

function t2() {
  let a = {b: 123}
  let {b} = a
}

单独执行 tsc ,正常编译。

报错信息

系统信息

 "dependencies": {
    "@tarojs/async-await": "^1.2.0-beta.11",
    "@tarojs/components": "^1.2.0-beta.11",
    "@tarojs/redux": "^1.2.0-beta.11",
    "@tarojs/redux-h5": "^1.2.0-beta.11",
    "@tarojs/router": "^1.2.0-beta.11",
    "@tarojs/taro": "^1.2.0-beta.11",
    "@tarojs/taro-alipay": "^1.2.0-beta.11",
    "@tarojs/taro-h5": "^1.2.0-beta.11",
    "@tarojs/taro-swan": "^1.2.0-beta.11",
    "@tarojs/taro-weapp": "^1.2.0-beta.11",
    "nerv-devtools": "^1.3.9",
    "nervjs": "^1.3.9",
    "react": "^16.6.3",
    "redux": "^4.0.0",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0",
    "taro-ui": "^1.5.1"
  },
  "devDependencies": {
    "@tarojs/plugin-babel": "^1.2.0-beta.11",
    "@tarojs/plugin-csso": "^1.2.0-beta.11",
    "@tarojs/plugin-less": "^1.2.0-beta.11",
    "@tarojs/plugin-sass": "^1.2.0-beta.13",
    "@tarojs/plugin-uglifyjs": "^1.2.0-beta.11",
    "@tarojs/webpack-runner": "^1.2.0-beta.11",
    "@types/react": "^16.4.8",
    "@types/webpack-env": "^1.13.6",
    "babel-eslint": "^8.2.3",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-jsx-stylesheet": "^0.6.5",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "eslint": "^4.19.1",
    "eslint-config-taro": "^1.2.0-beta.11",
    "eslint-plugin-import": "^2.12.0",
    "eslint-plugin-react": "^7.8.2",
    "eslint-plugin-taro": "^1.2.0-beta.11",
    "eslint-plugin-typescript": "^0.12.0",
    "typescript": "^3.0.1"
  }
  • 操作系统: OSX
  • Taro 版本 1.2.0-beta.11
  • 报错平台 weapp

补充信息
[可选]
[根据你的调查研究,出现这个问题的原因可能在哪里?]

@taro-bot
Copy link

taro-bot bot commented Dec 13, 2018

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@youzipi youzipi changed the title t's ts 编译报错 Dec 13, 2018
@yuche
Copy link
Contributor

yuche commented Dec 13, 2018

你应该把

const RequestHandler: (config: any) => Promise<any>

这样的拿出来,这种类型定义只能放在 *.d.ts 文件

@youzipi
Copy link
Author

youzipi commented Dec 14, 2018

我把文件里面一段一段移除后,居然报了这个错:
image
这是文件末尾,而且15行根本就没有。
最后发现是这里:

export type CompanyState = {
  readonly companyList: Company[],
  readonly buyList: Buyer[],
  readonly curCompany: Company,
}

// 注掉这一行后,可以正常编译
const INITIAL_STATE = <CompanyState>{}

ts 的报错定位不对。。。。

@yuche
Copy link
Contributor

yuche commented Dec 14, 2018

这个就是 babel typescript 的问题了,或许我们升级到 babel 7 会好一点,也可能不会。

@taro-bot
Copy link

taro-bot bot commented Dec 17, 2018

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

@taro-bot taro-bot bot removed the to be closed label Dec 19, 2018
@taro-bot taro-bot bot closed this as completed Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants