Custom Types have wrong `_type` key
See original GitHub issueLet’s have the following simple schemas:
const fooImage = {
type: 'image',
title: 'Top-level Image Type',
name: 'foo_image',
fields: [
{
title: 'Title',
name: 'title',
type: 'string',
},
],
};
const bar = {
type: 'document',
title: 'Bar',
name: 'bar',
fields: [
{
title: 'Nested Image Type',
name: 'nestedImage',
type: 'foo_image',
}
],
};
When generated, the FooImage
type is outputted like so:
export type FooImage = {
_type: "image";
asset: SanityAsset;
/**
* Title — `string`
*
*
*/
title?: string;
};
However, the _type
property is wrongly represented, as the _type
of it should in fact be foo_image
when referenced from the Bar
document.
I don’t see any use case requiring to have the “base type” present in the _type
property, but I may be wrong. Having the custom type there would better represent the actual Sanity API response format.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Proposal: new "invalid" type to indicate custom invalid states
Proposal A new invalid type that is not assignable to or from any other types. This includes not being assignable to or from...
Read more >How To Create Custom Types in TypeScript - DigitalOcean
In TypeScript, the syntax for creating custom types is to use the type keyword followed by the type name and then an assignment...
Read more >Typescript Type 'string' is not assignable to type - Stack Overflow
1) The first solution is to define a type for the size and export it from the foo.ts. This is good if when...
Read more >15 Typescript Mistakes To Avoid - SoftwareMill Tech Blog
Typescript took the Javascript world by storm. If you are a frontend developer, you should check those 15 common Typescript mistakes.
Read more >The Power of Custom Types - Andrew Scott Chapman - Medium
When you write a program using a strongly typed language, you will declare variables that have a specific data type. These types generally ......
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 merged a fix that should fix it for images and files but I think slug is still an issue. I’ll address in a separate PR once I get some time.
Great! I took a quick try at it sooner today and it proved to be maybe more complex to do that what I initially thought. Unfortunately, I don’t have enough time today to dig more into it.
Just to add to the example, it is not only
image
which is problematic. This should be the behavior for all Types (image
,file
,slug
,object
and so on…). I did a very quick fix this morning (only for image and file types), here is the code (quite incomplete and a test still, but feel free to use it).