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

build时声明文件typings.d.ts需要在哪里配置 #48

Closed
ksh033 opened this issue Jun 26, 2019 · 14 comments
Closed

build时声明文件typings.d.ts需要在哪里配置 #48

ksh033 opened this issue Jun 26, 2019 · 14 comments

Comments

@ksh033
Copy link

ksh033 commented Jun 26, 2019

build报错
error TS7016: Could not find a declaration file for module 'dom-helpers'. 'E:/nodeproject/ds/node_modules/_dom-helpers@3.4.0@dom-helpers/index.js' implicitly has an 'any' type.

@sorrycc
Copy link
Member

sorrycc commented Jun 26, 2019

没明白问题,这应该是 TypeScript 的使用问题。

@ksh033
Copy link
Author

ksh033 commented Jun 27, 2019

我的tsconfig.json配置是这样的

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "jsx": "react",
    "esModuleInterop": true,
    "sourceMap": true,
    "baseUrl": ".",
    "strict": true,
    "allowSyntheticDefaultImports":true,
    "noImplicitAny": true,
    "paths": {
      "@/*": ["src/*"]
    }
  },
  "include": ["src", "typings/index.d.ts"]
}

"typings/index.d.ts" 配置是这样的
declare module "dom-helpers";

noImplicitAny设置成false可以解决,但是, "typings/index.d.ts"这里面不是写声明了,为什么build
还是报Could not find a declaration file for module 'dom-helpers'.

当设置 .fatherrc esm:'rollup' namedExports配置不生效

@francecil
Copy link

declare module "dom-helpers";

这样从 dom-helpers 导出的模块都是any类型,
这时再设置noImplicitAny为true(不允许any), 肯定报错的吧,

要么 就设置为false,要么详细定义 declare module "dom-helpers" ?

noImplicitAny

@fengyun2
Copy link

fengyun2 commented Oct 23, 2019

@francecil @sorrycc

father-build读取声明文件typings.d.ts无效

"father-build": "^1.13.2"

image

  1. 我的 tsconfig.json 配置是这样的:
{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "module": "esnext",
    "target": "esnext",
    "lib": ["dom", "esnext"],
    "moduleResolution": "node",
    "jsx": "react",
    "esModuleInterop": true,
    "declaration": true,
    "noImplicitAny": false
  },
  "include": ["./packages", "./typings/"],
  "typings": "./typings/index.d.ts",
  "exclude": [
    "node_modules",
    "dist",
    "scripts",
    "build",
    "jest",
    "**/*.spec.ts",
    "es",
    "lib",
    "fixtures",
    "examples"
  ]
}
  1. ./typings/index.d.ts 配置如下:
declare module '*.css'
declare module '*.less'
declare module '*.scss'
declare module '*.svg'
  1. 目录结构:

image

@NexxLuo
Copy link

NexxLuo commented Apr 29, 2020

遇到一样的问题;如果说typings/index.d.ts未生效,但是vscode编辑器的确是没有报红线错误,只是father build的时候仍然会报错。怎么试都不行,这是ts的使用问题还是 father build的问题?

@aweiu
Copy link

aweiu commented Nov 20, 2020

@NexxLuo @ksh033 试试直接在 index.ts(你的入口文件)顶部:

/// <reference path="你的 xxx.d.ts 路径" />

@YeziZhao
Copy link

@aweiu 用你的 /// 方式解决了打包失败的问题

xueyang996 pushed a commit to LagrangeLabs/ii-admin-ui that referenced this issue May 12, 2021
入口文件增加d.ts文件说明

umijs/father#48 (comment)
@jiyingzhi
Copy link

还没有解决吗

@Astra-RX
Copy link

Astra-RX commented Jul 14, 2021

dumi 中打包同样问题,使用的是 babel 模式

@nieyao
Copy link

nieyao commented Jul 19, 2021

同 dumi 打包同样问题,babel模式

@PeachScript
Copy link
Member

参考:#227 (comment)

@SinHide
Copy link

SinHide commented Dec 24, 2021

参考:#227 (comment)

用这种方式改了,还是一样报错,并没解决问题

@nicaicaicaicai
Copy link

请问大家解决了吗?如何解决呢?

@PeachScript
Copy link
Member

这是 father 2 的 issue,father 4 直接项目根目录创建全局 d.ts 即可,以及如果 tsconfig.json 里配了 include 要确保 include 包含这个 d.ts

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