Comments (3)
@email2vimalraj I'm having a similar experience. One example is in https://github.com/stemmlerjs/ddd-forum/blob/master/src/shared/core/Result.ts.
Typescript Errors for Result.ts
src/shared/core/Result.ts(21,5): error TS2322: Type 'string | T | undefined' is not assignable to type 'string | T'.
Type 'undefined' is not assignable to type 'string | T'.
src/shared/core/Result.ts(22,5): error TS2322: Type 'T | undefined' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'T | undefined'.
Type 'undefined' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.
src/shared/core/Result.ts(43,32): error TS2345: Argument of type 'null' is not assignable to parameter of type 'string | U | undefined'.
from ddd-forum.
@email2vimalraj I'm having a similar experience. One example is in https://github.com/stemmlerjs/ddd-forum/blob/master/src/shared/core/Result.ts.
Typescript Errors for Result.ts
I'm new to Typescript and OOP so say whatever I will with a large grain of salt. In any case I wanted to jot down my thoughts of why this might be for my own learning with the hopes that someone might correct me.
The parameter 'value' in the constructor (line 8) is marked optional with the question mark, which makes it possible that it gets passed with undefined. In the class definition of Result, the private variable _value requires it to be T. Is it the case that T is not able to 'capture' undefined values as well?
The same counts for the error parameter (line 18).
In the public static function ok<U> (value?: U): Result<U>
returning null as parameter of the Result type probably also does not work because null means that the parameter is implicitly empty vis-a-vis set but undefined. Setting this to 'undefined' gets rid of the error for me.
from ddd-forum.
@email2vimalraj I'm having a similar experience. One example is in https://github.com/stemmlerjs/ddd-forum/blob/master/src/shared/core/Result.ts.
Typescript Errors for Result.tsI'm new to Typescript and OOP so say whatever I will with a large grain of salt. In any case I wanted to jot down my thoughts of why this might be for my own learning with the hopes that someone might correct me.
The parameter 'value' in the constructor (line 8) is marked optional with the question mark, which makes it possible that it gets passed with undefined. In the class definition of Result, the private variable _value requires it to be T. Is it the case that T is not able to 'capture' undefined values as well?
The same counts for the error parameter (line 18).
In the public static function
ok<U> (value?: U): Result<U>
returning null as parameter of the Result type probably also does not work because null means that the parameter is implicitly empty vis-a-vis set but undefined. Setting this to 'undefined' gets rid of the error for me.
I'm sorry for the very late reply. I wanted to thank you for pointing this out. The issue doesn't exist in the frontend version of the file. Adding null
to the possible types of error
and casting both this.error
and this._value
as T
resolves the issue:
Frontend
ddd-forum/public/app/src/shared/core/Result.ts
Lines 18 to 19 in ea39350
Backend
ddd-forum/src/shared/core/Result.ts
Line 8 in ea39350
ddd-forum/src/shared/core/Result.ts
Lines 18 to 19 in ea39350
This raises two questions for me:
- Why use
this._value
instead ofthis.value
when TypeScript offers theprivate
keyword (from SOLID Book) - How do we keep this DRY?
from ddd-forum.
Related Issues (20)
- Why entity id is implemented as Entity and not ValueObject?
- Encountered some errors while trying to run locally. (TS2339: Property 'body' does not exist on type 'DecodedExpressRequest'.)
- Atomically send event and update the database `outbox pattern`
- IDs as value objects fail equality check HOT 1
- [Question] Uniqueness validation & constructing domain objects in read operations (queries)
- There are no tests? HOT 1
- Guard against value objects
- UserId as Value Object || Entity ? HOT 1
- `null` values in the `Map.toDomain(c)` return. HOT 4
- [Question] How best to break up large use cases? HOT 1
- [Question] Sharing of errors between client & server. HOT 1
- [Question] Passing type and not using it in interface
- [Question]: Why not use Result everywhere? HOT 5
- [Question]: Usage of left/right monad & try/catch HOT 2
- [Question]: userId property in User class (also postId in Post etc.) HOT 3
- Making local dev easier and cleaning up the docs HOT 1
- Auto Logout if Refresh Token Expire frontend App?
- [Question] Typescript errors in Result class
- Injection of Domain Services
- Combined error in result issue
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 ddd-forum.