Comments (1)
Hi @vernak2539, I am sorry to disappoint you but if you are referring to assert(is<T>(val))
there is no test actually performed. You are just saying "trust me typescript I know val
is of type T
. If you where wrong you won't get build or runtime error when evaluating the assert
statement.
If there is a simple test that discriminate the type of your variable that TypeScript can understand, use it instead of is
this way you will get runtime validation.
If there isn't such a test and you want to have an error at runtime in case you where wrong with your assertion you can use typeGuard
.
In this case you probably want to put a message for the exception:
Be careful though, it is up to you to make sure that your check obj.id.startsWith("foo-")
actually validate that obj is of type Foo
.
from tsafe.
Related Issues (15)
- Assets HOT 18
- Dependency Dashboard
- lab/overwriteReadonlyProp.ts:34:63 Implicit conversion of a 'symbol' to a 'string' will fail at runtime HOT 10
- Introduce Extends HOT 11
- Possibly incorrectly typed objectEntries not returning an array type HOT 2
- Enable to typesafely compose Object.fromEntries and Object.entries HOT 2
- Ability to trigger warnings instead of errors HOT 1
- [Help Requested] Fixing Typos in Documentation HOT 5
- `tsafe` has improper esm exports HOT 11
- objectKeys should always return subset of string
- Asserting Two Types Not Throwing Error HOT 3
- Equals on enums reports incorrect results HOT 1
- Investigate tsd implementation
- assert incorrectly narrows type HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tsafe.