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

eslint对import Taro from @tarojs/taro的处理 #1332

Closed
nyrf opened this issue Dec 3, 2018 · 8 comments
Closed

eslint对import Taro from @tarojs/taro的处理 #1332

nyrf opened this issue Dec 3, 2018 · 8 comments

Comments

@nyrf
Copy link

nyrf commented Dec 3, 2018

问题描述
vscode下安装了eslint扩展后,会出现红线警示

import Taro, { Component } from '@tarojs/taro'
import { View, Button, Text } from '@tarojs/components'
import { observer, inject } from '@tarojs/mobx'

import './index.scss'

@inject('counterStore')
@observer
class Index extends Component {
  config = {
    navigationBarTitleText: '首页'
  }

  componentWillMount() {}

  componentWillReact() {
    console.log('componentWillRect')
  }

  componentDidMount() {}

  componentWillUnmount() {}

  componentDidShow() {}

  componentDidHide() {}

  increment = () => {
    const { counterStore } = this.props
    console.log(counterStore)
    counterStore.increment()
  }

  decrement = () => {
    const { counterStore } = this.props
    counterStore.decrement()
  }

  incrementAsync = () => {
    const { counterStore } = this.props
    counterStore.incrementAsync()
  }

  render() {
    const { counterStore } = this.props
    const result = counterStore.counter
    const all = counterStore.all
    console.log(result, 'result is.', all)
    return (
      <View className='index'>
        <Button onClick={this.increment}>+</Button>
        <Button onClick={this.decrement}>-</Button>
        <Button onClick={this.incrementAsync}>Add Async</Button>
        <Text>{result}</Text>
        <Text>{all}</Text>
      </View>
    )
  }
}

export default Index

期望行为
去除红线警示

报错信息

wx20181203-090356 2x

如果把import Taro, { Component } from '@tarojs/taro'改成import { Component } from '@tarojs/taro'
又出现
wx20181203-090408 2x

系统信息

  • 操作系统: osx 10.14
  • Taro 版本 1.2.0-beta.6
  • Node.js 版本 10.05
  • 报错平台 weapp
@taro-bot
Copy link

taro-bot bot commented Dec 3, 2018

欢迎提交 Issue~

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

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

Good luck and happy coding~

@yuche
Copy link
Contributor

yuche commented Dec 3, 2018

'Taro' is declared but its value is never read 是 typescript 的 提醒,你应该设置一下你的 tsconfig.json 或看看你的编辑器是不是 ts 模式检查 es

@yuche yuche closed this as completed in c7a50a6 Dec 3, 2018
@nyrf
Copy link
Author

nyrf commented Dec 3, 2018

@yuche 我的项目里没tsconfig.json这个文件,

"jsxFactory": "Taro.createElement",
tsconfig里原来就有 "jsxFactory": "Taro.createElement", 这行,你新加重了

@yuche
Copy link
Contributor

yuche commented Dec 3, 2018

image
这里不是 ts 的报错吗

@nyrf
Copy link
Author

nyrf commented Dec 3, 2018

我就只是用taro init 生成的模板,没用typescript, vscode也是什么也没安装,
wx20181203-113800 2x

wx20181203-113941 2x

@yuche
Copy link
Contributor

yuche commented Dec 3, 2018

image
你的编辑器要加这个

@doabit
Copy link
Contributor

doabit commented Dec 3, 2018

这个其实在tsconfig.json中添加"allowJs": true,这一句就可以了。如果init项目时没有选择typescript,要自己在项目目录下新建tsconfig.json,可以直接复制https://github.com/NervJS/taro/blob/master/packages/taro-cli/templates/default/tsconfigjson 这里的内容

@nyrf
Copy link
Author

nyrf commented Dec 3, 2018

谢谢,可以了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants