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类型问题 #24

Open
devsvc opened this issue Dec 16, 2020 · 9 comments
Open

TS类型问题 #24

devsvc opened this issue Dec 16, 2020 · 9 comments

Comments

@devsvc
Copy link

devsvc commented Dec 16, 2020

ERROR in C:/Users/x/x/node_modules/@femessage/v-gantt/src/utils/types.ts(1,26):
1:26 Cannot find module '@/utils/event-emitter' or its corresponding type declarations.
  > 1 | import EventEmitter from '@/utils/event-emitter'
      |                          ^
    2 |
    3 | export interface BaseItem {
    4 |   id: string
ERROR in  C:/Users/x/x/node_modules/@femessage/v-gantt/src/App.vue(26,58):
26:58 Argument of type '0' is not assignable to parameter of type 'string | undefined'.
    24 |   data() {
    25 |     const y = new Date().getFullYear()
  > 26 |     const m = `${new Date().getMonth() + 1}`.padStart(2, 0)
       |                                                          ^
    27 |     const d = (date) => `${y}-${m}-${date}`
    28 |     return {
    29 |       view: 'day',
ERROR in  C:/Users/x/x/node_modules/@femessage/v-gantt/src/App.vue(27,16):
27:16 Parameter 'date' implicitly has an 'any' type.
    25 |     const y = new Date().getFullYear()
    26 |     const m = `${new Date().getMonth() + 1}`.padStart(2, 0)
  > 27 |     const d = (date) => `${y}-${m}-${date}`
       |                ^
    28 |     return {
    29 |       view: 'day',
    30 |       data: [
@levy9527
Copy link

兄弟,你的预期是什么

@devsvc
Copy link
Author

devsvc commented Dec 17, 2020

不要报错,
后面两个是拷贝实例代码,属于我可以改的,我自己可以改,
但第一个就不受我控制了

@levy9527
Copy link

可以啊,找到�源码,修改一下,提个pr。我合了就发版本。

@devsvc
Copy link
Author

devsvc commented Dec 20, 2020

抱歉,TS我也不熟,第一个问题,我也不知道什么原因,不知道怎么改,
后面两个:
2: const m = ${new Date().getMonth() + 1}.padStart(2, ‘0’) 0加引号变成字符串类型
3: const d = (date: string) => ${y}-${m}-${date} date加上类型声明

@devsvc
Copy link
Author

devsvc commented Dec 21, 2020

初步确认, import EventEmitter from '@/utils/event-emitter' 改成 import EventEmitter from './event-emitter' 可以解决,
不知道写成这种@/的形式是为了达到什么效果呢, 目前我看到的资料没有提到这方面的内容

@levy9527
Copy link

好的,感谢你提供的信息,这边会安排处理一下的。

@donaldshen
Copy link
Collaborator

初步确认, import EventEmitter from '@/utils/event-emitter' 改成 import EventEmitter from './event-emitter' 可以解决,
不知道写成这种@/的形式是为了达到什么效果呢, 目前我看到的资料没有提到这方面的内容

这是路径别名,在 tsconfig 里配的。请问你是否是直接在项目代码里尝试引用 node_modules/@femessage/v-gantt 中的类型定义呢?

@gd4Ark
Copy link
Contributor

gd4Ark commented Dec 23, 2020

@donaldshen @devsvc 其实是 .d.ts 用到了 v-gantt 内部的类型定义,如果在项目中要用 v-gantt 的向外部暴露类型,就会调用到。

看:https://github.com/FEMessage/v-gantt/blob/dev/src/index.d.ts#L10
以及:https://github.com/FEMessage/v-gantt/blob/dev/docs/faq.md

@gd4Ark
Copy link
Contributor

gd4Ark commented Dec 23, 2020

初步确认, import EventEmitter from '@/utils/event-emitter' 改成 import EventEmitter from './event-emitter' 可以解决,
不知道写成这种@/的形式是为了达到什么效果呢, 目前我看到的资料没有提到这方面的内容

确实应该是这样

// src/utils/types.ts

- import EventEmitter from '@/utils/event-emitter'
+ import EventEmitter from './utils/event-emitter'

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

4 participants