typescript /// <reference types=“...“ />指令和模块import区别

(1)依赖全局库

	1、如果你的库依赖于某个全局库,使用/// <reference types="..." />指令:
	
	/// <reference types="someLib" />
	function getThing(): someLib.thing;

(2)依赖模块
	
	1、如果你的库依赖于模块,使用import语句:
	
	import * as moment from "moment";
	function getThing(): moment;

(3)依赖UMD库
	1、从全局库
		如果你的全局库依赖于某个UMD模块,使用/// <reference types指令:
		
		/// <reference types="moment" />
		function getThing(): moment;
	
	2、从一个模块或UMD库
	
		如果你的模块或UMD库依赖于一个UMD库,使用import语句:
		
		import * as someLib from 'someLib';
		
		不要使用/// <reference指令去声明UMD库的依赖!

猜你喜欢

转载自blog.csdn.net/weixin_43294560/article/details/114240771
今日推荐