前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Typescript: Getting Started

Typescript: Getting Started

作者头像
szhshp
发布2022-09-21 10:27:11
6640
发布2022-09-21 10:27:11
举报
文章被收录于专栏:szhshp 的第四边境中转站

Typescript Installation

  1. Create a Node.js project package.json. Quick one : npm init -y
  2. Add TypeScript (npm install typescript --save-dev)
  3. Add node.d.ts (npm install @types/node --save-dev)
  4. Init a tsconfig.json for TypeScript options with a few key options in your tsconfig.json (npx tsc --init --rootDir src --outDir lib --esModuleInterop --resolveJsonModule --lib es6,dom --module commonjs)

Typescript export error: XXX is not a module

代码语言:javascript
复制
 File 'C:/Users/ack47evii18es/Desktop/disqus-proxy/serverV2/src/config.ts' is not a module.

check the code:

index.ts :

代码语言:javascript
复制
import {config} from './config';

config.ts :

代码语言:javascript
复制
interface Config {
  port: number;
  api_key: string;
}

const globalConfig: Config = {
  port: 5050,
  api_key: '',
};

// module.exports = globalConfig; // delete this row
export const config = globalConfig;
代码语言:javascript
复制
 import {a} from 'something'; // you will get exported 'a'
 import a from 'something'; // you will get exported DEFAULT 'a'

Could not find a declaration file for module 'xxx'.

Try npm install @types/react-router-dom if it exists or add a new declaration (.d.ts) file containing declare module 'react-router-dom'; TS7016


.d.ts 是一个包含 declaration 的文件.

  1. 首先使用普通模式安装 [package]: npm i {package} -s
  2. 如果这个库里面有 .d.ts , 不需要任何后续的操作.
  3. 如果这个库里面没有 .d.ts , 那么需要提供 @types 2. https://www.npmjs.com/ 先到这里搜索一下看看能不能找到名为 @types/{packageName} 的 包 3. 如果可以找到安装 @types: npm i @types/{packageName} -D
    1. 如果不能找到搜索一下 github, 找到的话: npm install github:user project -D
  4. 如果找不到 types, 自己写一个

References

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-01-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Typescript Installation
  • Typescript export error: XXX is not a module
  • Could not find a declaration file for module 'xxx'.
  • References
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档