Is it possible to make a value passed to a function be a partial string (i.e., a substring) in TypeScript
Something along the lines of this?
function transform( str: Substring<'Hello world'> ) {
// ...
}
And when I then call the function I can pass a substring of that string
transform( 'world' );
// or
transform( 'Hello' );
// or
transform( 'ello' ); // Is valid because it exists in hello
// or
transform( 'orl' ); // Is valid because it exists in world
// Is not valid, altough individual letters exists
// they are not in the right order
transform( 'hlowrld' )
"Hello world".includes("world")? Because one might mean that"Hlo wld"is a substring of"Hello world", and the answer here very much depends on what you're actually asking."Hello world".includes("world"). So not just individual letter, they must be in order. I thought that this was pretty obvious in the question tho.