-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to assign a array inside a struct #17
Comments
If I try to instantiate via the following syntax, then it is working as expected:
But TSC throws type-mismatch error:
Hi @rbuckton, request you to please suggest something if possible. The type definitions of cc @KiranNiranjan @keerthi16 I will move the issue to DefinitelyTyped if it is type definition error instead of a bug in this library or in |
I'll take a look at the type definitions. I'm not an expert in I'll note I've been able to use the const WORD = ref.types.uint16;
const LONG = ref.types.int32;
export const IMAGE_DOS_HEADER = StructType({
e_magic: WORD,
e_cblp: WORD,
e_cp: WORD,
e_crlc: WORD,
e_cparhdr: WORD,
e_minalloc: WORD,
e_maxalloc: WORD,
e_ss: WORD,
e_sp: WORD,
e_csum: WORD,
e_ip: WORD,
e_cs: WORD,
e_lfarlc: WORD,
e_ovno: WORD,
e_res: ArrayType(WORD, 4),
e_oemid: WORD,
e_oeminfo: WORD,
e_res2: ArrayType(WORD, 10),
e_lfanew: LONG,
}); But I haven't used it as an initialized value yet, so I could have missed something in the typings. |
I noticed that if you just elide the data fields, the struct is instantiated fine, since it uses defaults for the arrays: const inchiAtom = new inchi_Atom({
x: 1.1,
y: 2.2,
z: 3.3,
num_bonds: 3,
isotopic_mass: 10,
radical: 2,
charge: -2,
}); While I can investigate the type changes I made, it does seem like a possible bug that you cant assign a typed array instance? I'd have to let the project authors weigh in on that. |
Many thanks for the response 👏
Noticed that coercion happens properly with export const ABCD = NAPIStructType({
radical: refNAPI.types.char,
});
const instance = new ABCD({
radical: "3",
});
strict.equal(ABCD.radical, "3".charCodeAt(0)); // <===== assertion PASSES
Upon following the error stack, it let to /**
* The "set" function of the Array "type" interface.
* Most likely invoked when setting within a "ref-struct" type.
*/
function set (buffer, offset, value) {
debug('Array "type" setter for buffer at offset', buffer, offset, value)
var array = this.get(buffer, offset)
var isInstance = value instanceof this
if (isInstance || isArray(value)) {
for (var i = 0; i < value.length; i++) {
array[i] = value[i]
}
} else {
throw new Error('not sure how to set into Array: ' + value)
}
} Here |
Current Scenario:
I am trying to instantiate an object of the above struct type:
Getting the following error:
Can anyone please suggest if this is a bug?
The text was updated successfully, but these errors were encountered: