使用Object.freeze
来使属性成为真实的常量。可参考 es6-const。
// global.ts
export const GlobalVariable = Object.freeze({
BASE_API_URL: 'https://orchome.com/',
//... more of your variables
});
使用import引用模块。
//anotherfile.ts that refers to global constants
import { GlobalVariable } from './path/global';
export class HeroService {
private baseApiUrl = GlobalVariable.BASE_API_URL;
//... more code
}