From 9dc3b0838973e9a7449abbfe22145cd5e8fa513a Mon Sep 17 00:00:00 2001 From: Li Yin Date: Wed, 3 Jan 2018 05:08:44 +0800 Subject: [PATCH] [ref-struct]: add opt parameter to allow create packed struct (#21932) * [ref-struct]: add opt parameter to allow create packed struct * Set TypeScript version to 2.2 for package depending on ref-struct --- types/ffi/index.d.ts | 1 + types/ref-struct/index.d.ts | 5 +++-- types/ref-struct/ref-struct-tests.ts | 12 ++++++++++++ types/ref-struct/tsconfig.json | 3 ++- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 types/ref-struct/ref-struct-tests.ts diff --git a/types/ffi/index.d.ts b/types/ffi/index.d.ts index 19107f373e..e3fc35f913 100644 --- a/types/ffi/index.d.ts +++ b/types/ffi/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/rbranson/node-ffi // Definitions by: Paul Loyd // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 /// diff --git a/types/ref-struct/index.d.ts b/types/ref-struct/index.d.ts index e0b47b288e..b45012d53e 100644 --- a/types/ref-struct/index.d.ts +++ b/types/ref-struct/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/TooTallNate/ref-struct // Definitions by: Paul Loyd // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 import ref = require('ref'); @@ -50,9 +51,9 @@ interface StructType extends ref.Type { /** The struct type meta-constructor. */ declare var StructType: { - new (fields?: {}): StructType; + new (fields?: object, opt?: object): StructType; new (fields?: any[]): StructType; - (fields?: {}): StructType; + (fields?: object, opt?: object): StructType; (fields?: any[]): StructType; } diff --git a/types/ref-struct/ref-struct-tests.ts b/types/ref-struct/ref-struct-tests.ts new file mode 100644 index 0000000000..194c9c7997 --- /dev/null +++ b/types/ref-struct/ref-struct-tests.ts @@ -0,0 +1,12 @@ +import ref = require("ref"); +import StructType = require("ref-struct"); + +const normalStruct = StructType({ + t: ref.types.uint8, + v: ref.types.long, +}); + +const packedStruct = StructType({ + t: ref.types.uint8, + v: ref.types.long, +}, {packed: true}); diff --git a/types/ref-struct/tsconfig.json b/types/ref-struct/tsconfig.json index 02963e3afd..5ebe7efa5f 100644 --- a/types/ref-struct/tsconfig.json +++ b/types/ref-struct/tsconfig.json @@ -17,6 +17,7 @@ "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts" + "index.d.ts", + "ref-struct-tests.ts" ] } \ No newline at end of file