Finally, files generated with kea-typegen will automatically import any types they can, and add the rest as type arguments
for kea<logicType<LocalType, LocalUser>>
You just need to add types to your actions
and reducers
.
import { Blog } from './blog'
import { logicType } from './logicType'
export const LocalType = 'YES' | 'NO'
const logic = kea<logicType<LocalType>>({ // ๐๐ฆ managed automatically by typegen
actions: {
openBlog: (id: number, blog?: Blog) => ({ id, blog }), // ๐ add types here
closeBlog: (answer: LocalType) => ({ answer }),
},
reducers: {
blogId: [
null as number | null, // ๐ null now, but sometimes a number ๐
{
openBlog: (_, { id }) => id,
closeBlog: () => null,
// use `actionTypes` instead of `actions`
[funLogic.actionTypes.randomBlogPage]: () => 4, // chosen by a fair dice roll
},
],
},
listeners: () => ({
closeBlog: ({ answer }) => { // no types needed here
console.log(answer)
}
})
})
Read the updated TypeScript guide to learn more.