Comments (8)
Thank you @Hookyns! No need to hotfix, I'll wait for update, it works fine in my current scenario, I was just testing how it works on different types I have
from tst-reflect.
@Hookyns is the future changes on the devel
branch? I have a potential fix to this problem along with a couple more changes. When I get time I can port those fixes to the devel
branch.
from tst-reflect.
Works like a charm!
Only bug I found during some testing, that Omit
fails when using [key: string]: any
extension in class:
function foo<T>() {
const type: Type = getType<T>()
console.log(type)
}
export class Temp {
id?: string
email?: string
// [key: string]: any // <--------
}
foo<Omit<Temp, 'email'>>()
Example output
TypeActivator {
_name: 'Omit',
_fullName: 'Omit',
_kind: 5,
_constructors: [],
_properties: [],
_indexes: [
IndexInfo {
_keyType: [LazyType],
_type: [LazyType],
readonly: false
},
IndexInfo {
_keyType: [LazyType],
_type: [LazyType],
readonly: false
}
],
_methods: [],
_decorators: [],
_typeParameters: [],
_ctor: undefined,
_ctorDesc: ConstructorImportActivator {},
_interface: undefined,
_isUnion: false,
_isIntersection: false,
_types: [],
_literalValue: undefined,
_typeArgs: [],
_conditionalType: undefined,
_indexedAccessType: undefined,
_functionType: undefined,
_genericTypeConstraint: undefined,
_genericTypeDefault: undefined,
_isGenericType: false,
_genericTypeDefinition: undefined,
_baseType: LazyType {
typeResolver: [Function (anonymous)],
resolvedType: TypeActivator {
_name: 'Object',
_fullName: 'Object',
_kind: 2,
_constructors: [],
_properties: [],
_indexes: [],
_methods: [],
_decorators: [],
_typeParameters: [],
_ctor: [Function: ctor],
_ctorDesc: ConstructorImportActivator {},
_interface: undefined,
_isUnion: false,
_isIntersection: false,
_types: [],
_literalValue: undefined,
_typeArgs: [],
_conditionalType: undefined,
_indexedAccessType: undefined,
_functionType: undefined,
_genericTypeConstraint: undefined,
_genericTypeDefault: undefined,
_isGenericType: false,
_genericTypeDefinition: undefined,
_baseType: undefined
}
}
}
If marked line is uncommented, then type is wrong, otherwise
from tst-reflect.
Ah yeah, I see. Didn't notice that typescript throws it away in indexer (anyway, I don't use these indexers now, it was added for migrating)
Thanks for making this amazing package, really appreciate the effort!
from tst-reflect.
Hello @Igorjan94,
this is an issue with the current implementation. These types are not handled properly; there is a new big upcoming update which change the way how are these types handled. It should be possible to hotfix this. I can do it in the current version if you want.
from tst-reflect.
@joeferner it can be main
, I do just minor fixes in the main
and devel
cuz I work on the next
version which change the transformer a lot.
from tst-reflect.
@Igorjan94, @joeferner
Should be fixed in [email protected]
and [email protected]
.
from tst-reflect.
Okay,.. I think I got it.
It works like intended IMHO because Omit creates new type alias which is object {}
and that object have some properties but it has indexer [key: string]: any
too which hides all other properties with string key. Those properties are subset of that indexer so TypeScript throws it away, because it is redundant information.
Try this:
function foo<T>() {
const type: Type = getType<T>()
console.log(type)
}
export class Temp {
id?: string
email?: string
[key: symbol]: any // <-------- SYMBOL key
}
foo<Omit<Temp, 'email'>>()
Now it generates the id
property, because it is not hidden under indexer anymore, because it does not match key type.
Generated metadata for that:
{
n: "Omit",
k: 5,
props: [{
n: "id",
t: _ßr.Type.store.wrap({
n: "string",
k: 2,
ctor: function () {
return Promise.resolve(String);
}
}),
am: 2,
acs: 0,
ro: false,
o: true
}],
indxs: [{
k: _ßr.Type.store.wrap({
n: "symbol",
k: 2,
ctor: function () {
return Promise.resolve(Symbol);
}
}),
t: _ßr.Type.store.wrap({
n: "any",
k: 2
}),
ro: false
}]
}
from tst-reflect.
Related Issues (20)
- `import * as _Br from 'tst-reflect'` is added to every compiled file HOT 4
- Add support of `isDefaultValueAvailable` and `getDefaultValue` on PropertyInfo and Parameter types HOT 6
- Support decorators from TS 4.8 HOT 2
- Unable to access parameter decorators HOT 2
- [BUG] Set not comparable HOT 1
- [Question] Anyway to add it as angular transformer HOT 18
- [BUG] tst-reflect: You call getType() method directly. You have probably wrong configuration, because tst-reflect-transformer package should replace this call by the Type instance. HOT 8
- [BUG] type metadata HOT 6
- Can't get `getType<T>()` to work HOT 5
- Participation in the new version of the system HOT 52
- [BUG] Watch mode HOT 1
- Can't get function to work with create-react-app HOT 3
- [BUG] Uncaught ReferenceError: _ßr is not defined HOT 4
- [Question] npm package using tst-reflect cannot be imported HOT 1
- [BUG] Union properties are broken HOT 5
- [BUG] TS 4.9 - "[ERR] tst-reflect: You call getType() method directly..." error when following base usage examples. HOT 17
- [Question] Comparison of Array types HOT 9
- [Question] How to get field type inside a decorator HOT 2
- [Question] Vite support HOT 3
- [Question] Does this work with functions? HOT 2
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 tst-reflect.