the deep meaning of ArrayBufferLike's typescript definition

后端 未结 1 446
广开言路
广开言路 2021-01-19 19:38

What\'s the meaning of the typescript definition for ArrayBufferLike?

interface ArrayBufferTypes {
    ArrayBuffer: ArrayBuffer;
}
type ArrayBu         


        
相关标签:
1条回答
  • 2021-01-19 20:29

    The reason is to allow ArrayBufferTypes to be extended using declaration merging.

    This single-member interface is defined in lib.es5.d.ts

    interface ArrayBufferTypes {
        ArrayBuffer: ArrayBuffer;
    }
    

    But the interface with the same name, but having another member, is defined in es2017.sharedmemory.d.ts

    interface ArrayBufferTypes {
        SharedArrayBuffer: SharedArrayBuffer;
    }
    

    When both type declarations are included in the program, declarations will be merged and the resulting union type

    type ArrayBufferLike = ArrayBufferTypes[keyof ArrayBufferTypes];
    

    will have two members now: ArrayBuffer and SharedArrayBuffer.

    0 讨论(0)
提交回复
热议问题