Giter Site home page Giter Site logo

Comments (8)

Igorjan94 avatar Igorjan94 commented on June 7, 2024 1

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.

joeferner avatar joeferner commented on June 7, 2024 1

@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.

Igorjan94 avatar Igorjan94 commented on June 7, 2024 1

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 $-$ works as intended

from tst-reflect.

Igorjan94 avatar Igorjan94 commented on June 7, 2024 1

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.

Hookyns avatar Hookyns commented on June 7, 2024

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.

Hookyns avatar Hookyns commented on June 7, 2024

@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.

Hookyns avatar Hookyns commented on June 7, 2024

@Igorjan94, @joeferner
Should be fixed in [email protected] and [email protected].

from tst-reflect.

Hookyns avatar Hookyns commented on June 7, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.