Assign an Array(PackedStringArray) to Array[String] reports error says it's not typed

Godot Version

v4.2.1.stable.flathub [b09f793f5]


I’m making a simple desktop app, it opens my task text file, devide them with double new lines and pick a random text (task) for me.
String.split() is perfect for this, but the returned PackedStringArray can’t use pick_random() or even [randi() % size()], so I reconstruct them into an Array and assign it to an Array[String].

(I know the line detection is bad I’ll figure it out later)
However, Godot refuses to assign it since the constructed Array wasn’t typed, although it’s impossible for it to hold anything other than String.
I can assign the value one by one with a loop, but then I’ll have to declare another array, I’m not sure if that’s worth the trouble.

Is there a simple way to copy the data while keep the array typed? Is there something more fundamental wrong I’m overlooking? Or do I just give up and use non-typed array?
Thanks for reading.

Current code:

extends Control

@onready var file_dialog = $FileDialog
@onready var label = $Label

var split_on_line_counts: int = 2

func split_txt(whole_text: String) -> Array[String]:
	var candidates: Array[String]
	candidates = Array(whole_text.split("\n".repeat(split_on_line_counts)))
	for candidate in candidates:
	return candidates

func _on_file_dialog_file_selected(path):
	var file =, FileAccess.READ)
	label.text = split_txt(file.get_as_text()).pick_random()

Why not?
Consider this works:

var s:String = "1,2,3,4,5,6"
var psa:PackedStringArray = s.split(",")
var n:String = psa[randi() % psa.size()]

I think you’re right, I can’t replicate, I must have wrote something wrong before.