Question: Is there a simple way to get a type reduced to only primitives?
See original GitHub issueFor example, if I have a type that is:
type Company = {
name: string
employees: Person[]
}
type Person = {
name: string
age: number
}
How can I get the deeply interpreted type, so that in Company instead of a reference to another type alias I get the properties of Person in there.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Primitive Types - Wikibooks, open books for an open world
All the primitive types have a fixed size. Thus, the primitive types are limited to a range of values. A smaller primitive type...
Read more >Is there a way to create nominal types in TypeScript that ...
I would like to represent these variables with the basic number primitive, but disallow assignment of a longitude to a latitude variable in...
Read more >Data Types in Java | Primitive and Non-Primitive Data Types
This article on Data Types in Java will give you a brief insight into various primitive and non primitive data types in Java...
Read more >Primitive Obsession - Refactoring.Guru
Even better, move the behavior associated with this data into the class too. For this task, try Replace Data Value with Object.
Read more >When Primitives Behave Like Objects - KIRUPA
Strings Aren't the Only Problem. Because of how fun and playful they are (kind of like a Golden Retriever!), it's easy to pick...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Iβm currently solving exactly same problem and I wrote a little script for it. My use case is to build a function that makes it more explicit which APIβs a given shared type affects - when changed. So if you changed a type - you will see all the public boundary interface functions/api this change affects because it would lead to a jest snapshot change.
E.g. for this type:
it prints:
This is my first attempt at this and the first time Iβm using
ts-morph
- I welcome any feedback π https://gist.github.com/zaripych/963fa6584524e5b446b70548dbabbf65Iβm almost there, but currently have a problem for properties that do not have declared types. E.g.
getDeclarations()
returns an empty array. π€― Does anybody know if there is an additional way to get a property type?@zaripych you just helped me fix a problem in which types created with
Omit
where missing keys. I fixed it by doinggetTypeAtLocation
, just like you. Thanks a lot!