Closed rjkz808 closed 3 years ago
P.S. I know that it's possible to do something like this:
const arr: String[] = TypedJSON.parseAsArray('["a", "b", "c"]', String);
But under the hood it'll use primitive value constructors (Number/String, etc.) instead of primitive values themself.
Hi @rjkz808, why do you think it will use the constructors? By default, when TypedJSON sees a primitive it uses it directly (see deserializeDirectly
function). The code below prints [ 'a', 'b', 'c' ]
, and true
as expected.
const result = TypedJSON.parseAsArray(
'["a", "b", "c"]',
String,
);
console.log(result);
console.log(result[0] === 'a');
Is it possible to deserialize collections of primitive values with
typedjson
without defining a schema? I mean something like this: