3 ms·
TypeScript is just for compile time. You can pop() every element out of the array at runtime with no error. This compiles with no issue - https://www.typescript
by MichaelNolan 2y ago
TypeScript is just for compile time. You can pop() every element out of the array at runtime with no error. This compiles with no issue - https://www.typescriptlang.org/play/?#code/C4TwDgpgBAcg9gOwKIFsygIICcsEMQA8AKgHxQC8UA2kQDRQB0TRVAuqwNwBQXAxogGdgUFCGx4QALliJU6MTnwEEAVxQAjCFjKUqARnoAmegGZOPAPQWoAJQgo4AN2jAAFtAA2uIVAgf7EAjAXKLi+AxgcGAAFACU3HyCcP4MHnAA5tGhiiDxUFZQAPIqwGAl0vpGrJbWdg7OUG6e3sJ+AUFQuOm4AJYIIQoSEVFxCfwIAskQqRlZg-h5BcWl5dR61VwFdU4u7lBePm0ogcJdvf3ZQ5Ex8TzjkylpmZcLHPnWy2XAFdVAA https://www.typescriptlang.org/play/?#code/C4TwDgpgBAcg9gOwK...
- tantalor 2y agoIf that's true, then how is a type like this (non-empty array) useful at all, if it can't be relied on at runtime? TS should say, you can't pop() this array, unless TS can infer it has >1 elements. Otherwise it can enter a state at runtime which doesn't conform to the type. That seems bad!