field-form icon indicating copy to clipboard operation
field-form copied to clipboard

readonly array cannot be assigned to the mutable type 'InternalNamePath'

Open nichtsam opened this issue 3 years ago • 0 comments

https://github.com/react-component/field-form/blob/d7892873e9eee6e4c618d4289fcdbc9ee240f68f/src/interface.ts#L4

For reusability and readability purpose, I like to have my NamePath stored in constant variable on the top of the file.

To have type support I need the variable's type to be string literal tuple. The simplest way to make an array a string literal tuple is to add as const after it.

However, as const also add readonly to them, making it not assignable to InternalNamePath.

I like the simplicity of as const and I don't think the InternalNamePath is ever actually mutated.

would it be possible to add readonly in front of (string | number)[] to make the InternalNamePath support this?

nichtsam avatar Aug 03 '22 07:08 nichtsam