Comments (6)
I agree, I think it would be more productive to use unknown
and remove the Json
type entirely. Then we can cast freely and not violate any ESLint rules.
from postgres-meta.
We probably want to type this as generics here, ie.
export type Json<T=void> = string | number | boolean | null | T | T[]
I will transfer this to postgres-meta repo as it's a feature for the types generator.
from postgres-meta.
Thanks, can you please link to where you moved it?
from postgres-meta.
@sweatybridge from my experimentation, using generics wouldn't make any difference, since the type in the exported interface would need to either be Json
using the default type parameter, or would need to be instantiated with some fixed type parameter.
x: Json
y: Json<SomeFixedTypeParam>
Alternatively we make the Database
type a generic type, but that's not suitable, and would force all Json
types within to take on the same type anyway.
@inorganik the problem with using something like any
or even doing something like:
export type Json<T = Record<string, any>> = string | number | boolean | null | T | Json<T>[]
is that it would likely break many people's builds, as a lot of projects will have the no-explicit-any
rule enabled in eslint.
We could add an ignore at the top of the file, but that doesn't solve the problem for anyone - some people use other linters.
People could manually add the ignore by piping through another command, but it's not really fair to expect people to do that.
Appreciate that I'm providing problems not solutions here, but I also feel like doing:
const ingredient = result as unknown as Ingredient
Isn't too egregious, and is fairly common anyway.
Actually, I came up with a (potential) solution!
Since you're likely to need to use as
anyway to type things coming from Json
, we could just change the Json
type to be the following:
export type Json = string | number | boolean | null | unknown | Json[]
const result: Json = { id: 1, name: 'Berries', quantity: '1 cup' }
const i: Ingredient = result as Ingredient
This then throws no errors.
However, this identical to doing export type Json = unknown
, so we could just remove Json
entirely, if we were to go down this route. Interested to hear what people's opinions are.
from postgres-meta.
I agree, I think it would be more productive to use
unknown
and remove theJson
type entirely. Then we can cast freely and not violate any ESLint rules.
I think the first step would be to change the export to export type Json = unknown
, but mark it as deprecated, and perhaps include a warn message in the Supabase CLI.
from postgres-meta.
Related Issues (20)
- v0.61.1 introduces bug in typescript generation for computed column HOT 3
- Unable to run postgres-meta development
- typescript generated type of pgvector/vector is string HOT 5
- Generate types for foreign tables HOT 5
- Generating types for a postgresql array results in Typescript unknown property HOT 4
- Feat: Indexes HOT 1
- supabase gen types generates duplicate identifiers HOT 3
- gentype producing wrong type for inner join HOT 1
- Typegen is not respecting unique table constraint HOT 3
- Permission denied error when generating types HOT 3
- SSL connection error with "PG_META_DB_SSL_ROOT_CERT" and "rejectUnauthorized" misconfiguration HOT 3
- Stopping the container is slow, resorting to SIGKILL
- How to get online postgre-meta version? HOT 1
- Hardcoded metadata resulting in broken TypeScript type generation from the Supabase CLI HOT 1
- sslmode=require ignored on postgresql URL with gen types --db-url HOT 3
- Gen type throws an exception when table has no columns HOT 2
- Type generation script does not pick up correct type when a SQL function returns data from other table HOT 1
- Composite types can be null
- Generated DB types do not include function property in Table HOT 1
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 postgres-meta.