작성
·
170
0
interface customArray<T>{
filter<S extends T>(callback:(v:T, index: number, array:T[]) => v is S): S[]
}
const sample1: customArray<string> = ["1", "2"]
const value = sample1.filter((value, index): value is string => Number(value) > 1)
강의에서 구현하신 custom filter는 custom type guard
로 별도 리턴 분기처리를 하지않았는데 어떻게 true 케이스들만 필터링 할수 있는지 궁금합니다.
저의 개인적인 생각은 callback의 반환값으로 value is string
를 반환하는데 위의 케이스를 바탕으로 value는 string 형식이기 때문에 true
가 됩니다
때문에 callback 메서드 수행시 false 반환값은 무시되고 true 반환값들만 리턴된다라고 추측이되는데 이 추측이 맞는지 궁금합니다