Closed Yhprum closed 18 hours ago
maybe we could add a QuoteFields
type that I could add to the array like
const YAHOO_QUOTE_FIELDS: QuoteFields = [...
you can close this if it's a duplicate of #807, not 100% sure
Hey, @Yhprum. I think we need the as const
for the string part, no? e.g.
- const YAHOO_QUOTE_FIELDS = ["regularMarketPrice"] as const;
+ const YAHOO_QUOTE_FIELDS = ["regularMarketPrice" as const];
That fixes the error for me.
However, I also like your idea of exporting QuoteField
(especially since you'll get nice text completion in your editor), so that will be in the next release:
import type { QuoteField } from "yahoo-finance2/dist/esm/src/modules/quote";
const YAHOO_QUOTE_FIELDS: QuoteField[] = ["regularMarketPrice"];
Thanks for raising this :pray:
Out in 2.13.0.
Thanks a bunch for this (and my other issues)! This works great with the exported type. The reason I didn't want to to the as const
for each string is I have an array of ~20 fields I include in the request and it was super messy adding them to each one.
Appreciate the quick response!
Hey, sure, and thanks for reporting back! These are all a few quirks that slipped through our new typescript / validation architecture so very grateful to have the reports and get to crunch them asap. So thanks again 🙏😁
Bug Report
Describe the bug
Typescript error when passing a prebuilt array into
quote
fieldsMinimal Reproduction
const YAHOO_QUOTE_FIELDS = ["regularMarketPrice"] as const; yahooFinance.quoteCombine("AAPL", { fields: YAHOO_QUOTE_FIELDS })
Environment
Browser or Node: node Node version (if applicable): 20.9.0 Npm version: 10.1.0 Browser verion (if applicable): Library version (e.g.
1.10.1
): 2.12.5Additional Context
since the quote fields are the list of options and not a generic
string[]
, I can't pass an array of options in like I was previously (this is good though, I like the stricter typing of options. However the way I generaly deal with this is addingas const
after the array to make the type the literal strings instead of a generic string array, but I get this error now.The type <myType> is 'readonly' and cannot be assigned to the mutable type <yourType>