Global Method

소개

src/env.d.ts 파일

declare global { // 전역 타입으로 선언
    interface dlog {
        (text: string) : void;
    }

    var dlog : dlog; // 해당 변수를 전역적으로 쓰려면 var

    var dlog2 = (text: string) => void; // 함축해서 쓸 수 있음.
}

export {};  // 모듈이라고 선언하는 효과

구현파일

const root = globalThis as any; // 아스트로의 루트 객체

root.dlog = (text: string) => {  // 루트 객체에 연결
    console.log(text);
}

적용 (진입점이나 루트 레이아웃)

import 구현파일;

사용 (아무 ts 구역에서)

dlog('hi');