-
|
I'm having trouble when I need to pass an argument to Expected result: // Items.ts
import type Price from '../Price'
export default interface Items {
id: number
name: string
prices: Price[]
}eg: Price serializer # PriceSerializer.rb
attributes :amount
def amount
"#{options[:currency_code]} object.amount"
endI can call the serializer as this in controller PriceSerializer.render(price, currency: 'USD')by using has_many, I can't pass an argument # ItemSerializer.rb
attributes :name
has_many :prices, serializer: PriceSerializer # doesn't accept optionsSo to overcome this # ItemSerializer.rb
attributes :name
attribute
# PriceSerializer[] won't work since its not an actual class
type PriceSerializer
def prices
PriceSerializermany(object.prices, currency_code: options[:currency_code])
endHowever in the resultant types: // Items.ts
import type Price from '../Price'
export default interface Items {
id: number
name: string
prices: Price // should be Price[]
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hi Alexandr! Passing In the meantime, you could try something like: type "Price[]"
def prices
PriceSerializer.many(object.prices, options)
endAnd then create an import type { Price } from '~/types/serializers'
export type { Price as default } |
Beta Was this translation helpful? Give feedback.
Hi Alexandr!
Passing
optionsis a missing feature inoj_serializersthat I'd like to add at some point (if I manage to do so without introducing performance regressions for the cases whereoptionsare not used).In the meantime, you could try something like:
And then create an
app/frontend/types/Price.tsfile where you re-export the generated type as a custom type: