Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

默认的lib,应该只包含 es2016 , 不应该包含DOM #14

Closed
John0King opened this issue Aug 2, 2018 · 6 comments
Closed

默认的lib,应该只包含 es2016 , 不应该包含DOM #14

John0King opened this issue Aug 2, 2018 · 6 comments

Comments

@John0King
Copy link

当跟wx一块工作的时候, tsconfig.json 里面应该只包含 lib:["es2016"] , 因为所有的DOM API 在微信中都不可用

interface Console 却包含在 dom 中, 所以 we-app.d.ts 里面应该包含 Console 的定义, 另外 setTimeout setInterval clearInterval 也需要定义,
下面是我写的定义, Console 是从 dom.d.ts 里面 偷的 :P


interface Console {
    assert(condition?: boolean, message?: string, ...data: any[]): void;
    clear(): void;
    count(label?: string): void;
    debug(message?: any, ...optionalParams: any[]): void;
    dir(value?: any, ...optionalParams: any[]): void;
    dirxml(value: any): void;
    error(message?: any, ...optionalParams: any[]): void;
    exception(message?: string, ...optionalParams: any[]): void;
    group(groupTitle?: string, ...optionalParams: any[]): void;
    groupCollapsed(groupTitle?: string, ...optionalParams: any[]): void;
    groupEnd(): void;
    info(message?: any, ...optionalParams: any[]): void;
    log(message?: any, ...optionalParams: any[]): void;
    markTimeline(label?: string): void;
    profile(reportName?: string): void;
    profileEnd(): void;
    table(...tabularData: any[]): void;
    time(label?: string): void;
    timeEnd(label?: string): void;
    timeStamp(label?: string): void;
    timeline(label?: string): void;
    timelineEnd(label?: string): void;
    trace(message?: any, ...optionalParams: any[]): void;
    warn(message?: any, ...optionalParams: any[]): void;
}

declare var console: Console;

/**
 * 定期执行特定的处理程序
 * @param handler 处理程序
 * @param waitTime 等待的时间
 */
declare function setTimeout(handler: () => any, waitTime: number): number;

/**
 * 每隔一段时间执行特定的处理程序
 * @param handler 处理程序
 * @param waitTime 每次执行间隔的时间
 */
declare function setInterval(handler: () => any, waitTime: number): number;

/**
 * 清理由 setInterval 产生的 timer
 * @param timerId timer 的id
 */
declare function clearInterval(timerId: number);

/**
 * 清理由 setTimeout 产生的timer
 * @param timerId timer 的 id
 */
declare function clearTimeout(timerId: number);

declare function require(lib: string): any;

setImmediateclearImmediate 我没定义, 主要是没用到,也不确定 小程序支持

@emeryao
Copy link
Owner

emeryao commented Aug 2, 2018

I think the dom declarations should be included in the we-app project while developing
You should figure out which dom interfaces are supported by we-app or not by yourself

@emeryao emeryao closed this as completed Aug 2, 2018
@John0King
Copy link
Author

@emeryao so far, I can't find any dom interface that can be use in wechat mini program

@emeryao
Copy link
Owner

emeryao commented Aug 2, 2018

what about the console you said in the issue description

@John0King
Copy link
Author

So I think the console in dom.d.ts is a browser console , maybe wechat miniprogram use the same console object , but It 's more like a MiniProgramConsole .
Have the dom in the type definition may make us easily use any present api that browse already have , but it also give us an unreliable type definition (a method or class may pass by type check , but it may be just a undefined )

that's also why typescript separate the whole type definition into several file, and allowd use choose different lib

please reconsider this for someone who use the "strict type definition "

@emeryao
Copy link
Owner

emeryao commented Aug 2, 2018

I think your so called MiniProgramConsole is the same with window.console in dom

@John0King
Copy link
Author

but things like WebSocket and Worker are different than browser dom api, and there are many api that wechat do not support.

if the type definition is incorrect , what's the different with js + "AutoComplete" +"Bable"

we are using typescript , shouldn't us make the type definition correct ?

Repository owner locked and limited conversation to collaborators Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants