AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
[TOC] ## 概述 ``` namespace span{ /*需要用 export 导出*/ export class demo{ foo(name:string):string{ return name; } } } let demo = new span.demo; demo.foo("abc") ``` ## 多个文件中有相同的命名空间 IShape.ts ``` namespace Drawing { export interface IShape { draw(); } } ``` Circle.ts ``` /// <reference path = "IShape.ts" /> namespace Drawing { export class Circle implements IShape { public draw() { console.log("Circle is drawn"); } } } ``` TestShape.ts ``` /// <reference path = "IShape.ts" /> /// <reference path = "Circle.ts" /> function drawAllShapes(shape:Drawing.IShape) { shape.draw(); } drawAllShapes(new Drawing.Circle()); ``` 编译执行 `tsc --out app.js TestShape.ts ` ## 嵌套命名空间 ``` namespace demo1{ export namespace demo2{ export class demo3{ demo4(){ console.log("hello"); } } } } let demo3 = new demo1.demo2.demo3(); demo3.demo4(); ```