typia icon indicating copy to clipboard operation
typia copied to clipboard

Primitive<T> does not preserve positional array elements in dynamic arrays

Open wshart opened this issue 9 months ago • 4 comments

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'

wshart avatar Feb 26 '25 21:02 wshart

@kakasoo Can you help?

samchon avatar Feb 27 '25 00:02 samchon

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?

w0rdgamer avatar Mar 08 '25 23:03 w0rdgamer

OMG. I saw this now. Do you want me to fix it?

kakasoo avatar Mar 09 '25 01:03 kakasoo

@w0rdgamer Welcome your contribution.

samchon avatar Aug 09 '25 16:08 samchon