typia
typia copied to clipboard
Primitive<T> does not preserve positional array elements in dynamic arrays
Bug Report
Thank you for the incredible library 🙂
📝 Summary
Write a short summary of the bug in here.
- Typia Version: 7.6.4
- Expected behavior:
Primitive<["asdf", ...string[], "zxcv"]> = ['asdf', ...string[], 'zxcv'] - Actual behavior:
Primitive<["asdf", ...string[], "zxcv"]> = string[]
⏯ Playground Link
Demo on StackBlitz (wait for install)
💻 Code occuring the bug
import typia, { Primitive } from 'typia';
type X = ['asdf', ...string[], 'zxcv'];
type ThisTypeIsOnlyStringArray = Primitive<X>;
const value = JSON.stringify(['asdf', 'qwer', 'zxcv']);
const y = typia.json.assertParse<X>(value); // y has type string[], not X
const z = y[0]; // z has type string, not 'asdf'
@kakasoo Can you help?
https://github.com/samchon/typia/blob/6445f45a8d273d2c07e0cac9b818907767ae1a2c/src/typings/IsTuple.ts#L6-L8
Looks like IsTuple is failing for variable-length tuples because of this code. @samchon should I take a shot at fixing it?
OMG. I saw this now. Do you want me to fix it?
@w0rdgamer Welcome your contribution.