Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 重写lib.d.ts中定义的变量_Typescript - Fatal编程技术网

Typescript 重写lib.d.ts中定义的变量

Typescript 重写lib.d.ts中定义的变量,typescript,Typescript,我已经为WebWorkers API输入了以下内容。在文件的最底部有一行描述self对象。lib.d.ts中使用了相同的变量名,当我添加对WebWorker.d.ts的引用时,我看到self有类型窗口,而不是专用WorkerGlobalScope。 我应该修正什么来覆盖此定义 interface WorkerNavigator extends NavigatorID, NavigatorOnLine { } interface WorkerUtils extends WindowTimers,

我已经为WebWorkers API输入了以下内容。在文件的最底部有一行描述self对象。lib.d.ts中使用了相同的变量名,当我添加对WebWorker.d.ts的引用时,我看到self有类型窗口,而不是专用WorkerGlobalScope。 我应该修正什么来覆盖此定义

interface WorkerNavigator extends NavigatorID, NavigatorOnLine {
}

interface WorkerUtils extends WindowTimers, WindowBase64 {
    importScripts: (...urls: string[]) => void;
    navigator: WorkerNavigator;
}

interface WorkerLocation {
    href: string;
    protocol: string;
    host: string;
    hostname: string;
    port: string;
    pathname: string;
    search: string;
    hash: string;
}

interface WorkerGlobalScope extends EventTarget, WorkerUtils {
    self: WorkerGlobalScope;
    location: WorkerLocation;

    close: () => void;
    onerror: Function;
    onoffline: Function;
    ononline: Function;
}

interface DedicatedWorkerGlobalScope extends WorkerGlobalScope {
    postMessage:(message:any, ...args:any[])=>void;
    onmessage: Function;
}

declare var self: DedicatedWorkerGlobalScope;
UPD: 尽管有上面的代码,我还是必须使用下面的方法。看来自我的定义没有被推翻

/// <reference name="WebWorkers.d.ts" />

declare var self: DedicatedWorkerGlobalScope;
//
声明var self:专用WorkerGlobalScope;

该代码是有效的,您可以看到它适用于的最新版本

TypeScript接口是开放式的:

interface Foo{
    bar:number;
}

// Continue to add members to Foo: 
interface Foo{
    baz: number;
}

// The followin is valid : 
var foo:Foo;
foo.bar = 123; 
foo.baz = 456; 

VS 2013 RC中的TypeScript 0.9.1,这对我来说很好…它可以工作,但我必须把
声明var self:DedicatedWorkerGlobalScope当我使用此类型时,到处都是