mosesintech
mosesintech
TTCTheo's Typesafe Cult
Created by mosesintech on 2/13/2024 in #questions
html-react-parser and "Unsafe call of an `any` typed value".
Thank you for the reply 🙂 The parser can take a string, so I assumed {parser(${item.label})} would work. The function already comes with a return type, which is why I'm pretty confused. The package defines it as typeof domToReact. As far as I can tell, it doesn't return any. Could the linter just be wrong here?
5 replies
TTCTheo's Typesafe Cult
Created by mosesintech on 9/20/2023 in #questions
TypeScript error: Type 'string' is not assignable to union value
Actually @shiroyasha9, it fixed the compile issue I had but it isn't actually checking the type right. If I have requiredIndicator as "TEXTs", it still works. Shouldn't that cause an error?
10 replies
TTCTheo's Typesafe Cult
Created by mosesintech on 9/20/2023 in #questions
TypeScript error: Type 'string' is not assignable to union value
You are exactly right. I took a look at how I was using the package in the wild and realized I was doing exactly that, so past me must have known something that present me forgot:
import { useStaticQuery, graphql } from "gatsby"

// import types
import type { Form } from "wpgravitybundle"

const useGravityData = () => {
const { allWpGfForm } = useStaticQuery(
graphql`
query FormQuery {
allWpGfForm {
nodes {
databaseId
formFields {
nodes {
databaseId
type
visibility
pageNumber
}
}
submitButton {
text
type
}
}
}
}
`
)
const allForms = allWpGfForm as { nodes: Form[] }
return { allForms }
}

export default useGravityData
import { useStaticQuery, graphql } from "gatsby"

// import types
import type { Form } from "wpgravitybundle"

const useGravityData = () => {
const { allWpGfForm } = useStaticQuery(
graphql`
query FormQuery {
allWpGfForm {
nodes {
databaseId
formFields {
nodes {
databaseId
type
visibility
pageNumber
}
}
submitButton {
text
type
}
}
}
}
`
)
const allForms = allWpGfForm as { nodes: Form[] }
return { allForms }
}

export default useGravityData
Thanks for the help @shiroyasha9. You're the best
10 replies
TTCTheo's Typesafe Cult
Created by mosesintech on 9/20/2023 in #questions
TypeScript error: Type 'string' is not assignable to union value
On this branch (feature/typesafe-v1). Running npm run start spins up the example app in example/src/app.tsx using data from example/data/query.json https://github.com/TotalityWorks/wpgravitybundle/blob/feature/typesafe-v1/example/src/app.tsx I get the error when I run start. Full error message:
[tsl] ERROR in /Users/maxcosme/Development/TotalityWorks/wpgravitybundle/example/src/app.tsx(82,18)
TS2322: Type '{ databaseId: number; cssClass: null; customRequiredIndicator: null; dateCreated: string; dateCreatedGmt: string; description: string; descriptionPlacement: string; firstPageCssClass: string; ... 18 more ...; formFields: { ...; }; }' is not assignable to type 'Form'.
Types of property 'requiredIndicator' are incompatible.
Type 'string' is not assignable to type '"TEXT" | "ASTERISK" | "CUSTOM" | null | undefined'.
ts-loader-default_e3b0c44298fc1c14

webpack 5.75.0 compiled with 1 error in 10476 ms
[tsl] ERROR in /Users/maxcosme/Development/TotalityWorks/wpgravitybundle/example/src/app.tsx(82,18)
TS2322: Type '{ databaseId: number; cssClass: null; customRequiredIndicator: null; dateCreated: string; dateCreatedGmt: string; description: string; descriptionPlacement: string; firstPageCssClass: string; ... 18 more ...; formFields: { ...; }; }' is not assignable to type 'Form'.
Types of property 'requiredIndicator' are incompatible.
Type 'string' is not assignable to type '"TEXT" | "ASTERISK" | "CUSTOM" | null | undefined'.
ts-loader-default_e3b0c44298fc1c14

webpack 5.75.0 compiled with 1 error in 10476 ms
10 replies
TTCTheo's Typesafe Cult
Created by mosesintech on 5/17/2023 in #questions
SVGs in Next
I like that a lot! Don't know why I never thought of it before, but it solved all the issues I was having. Thanks Ronan!
5 replies