4

Say my function f takes an argument, x, of type string. But not any string, only strings of length n.

Is it possible to enforce this using the type system?

1 Answer 1

2

No, it is not possible to do this in Typescript as types.

Sign up to request clarification or add additional context in comments.

1 Comment

There is an open proposal for regex-validated types though, but nothing you can do currently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.