Bỏ qua

Dùng string ts để bắt kiểu cho chuỗi được tốt hơn

😬 The problem

When you are working with literal strings, the string manipulation functions only work at the runtime level and the types don’t follow those transformations. You end up losing type information and possibly having to cast the result.

const str = 'hello-world'
const result = str.replace('-', ' ') // you should use: as 'hello world'
//    ^? string

🤓 The solution

This library aims to solve this problem by providing a set of common functions that work with literal strings at both type and runtime level.

import { replace } from 'string-ts'

const str = 'hello-world'
const result = replace(str, '-', ' ')
//    ^ 'hello world'

Nguồn:: GitHub - gustavoguichard/string-ts: Strongly typed string functions

Cập nhật lần cuối : 20 tháng 4, 2024
Tạo : 20 tháng 4, 2024