This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
So I am using TypeScript for the first time, and I really like that it prevents me from making really stupid errors that I used to make all the time. But the main way I know to get it to not yell at me is to declare an interface above the default function that is going to be passed through, make the props of type of the declared interface, and there we go. This is really straight forward for custom things you make yourself, but I am confused on how to do things for components imported from libraries. The first error I get is some version of these two errors in conjunction:
Type 'string' is not assignable to type 'keyof StackNavigatorProps'.ts(2322)
types.d.ts(349, 5): The expected type comes from property 'name' which is declared here on type 'IntrinsicAttributes & RouteConfig<StackNavigatorProps, keyof StackNavigatorProps, StackNavigationState<ParamListBase>, StackNavigationOptions, StackNavigationEventMap>'
And then there is also some version of these two errors in conjunction:
No overload matches this call.
Argument of type '[string]' is not assignable to parameter of type '[screen: "userName", params: { name: string; nextPage: string; question: string; subtitle: string | null; options: any[] | null; answer: null; needsImportance: boolean; importance: string | null; skippable: boolean; ... 6 more ...; index: number; }] | [screen: ...] | [screen: ...]'.
Type '[string]' is not assignable to type '[screen: "pronouns", params: { name: string; nextPage: string; question: string; subtitle: string | null; options: any[] | null; answer: null; needsImportance: boolean; importance: string | null; skippable: boolean; ... 6 more ...; index: number; }]'.
Source has 1 element(s) but target requires 2.
Overload 2 of 2, '(options: { key: string; params?: { name: string; nextPage: string; question: string; subtitle: string | null; options: any[] | null; answer: null; needsImportance: boolean; importance: string | null; ... 7 more ...; index: number; } | undefined; merge?: boolean | undefined; } | ... 4 more ... | { ...; }): void', gave the following error.
Argument of type 'string' is not assignable to parameter of type '{ key: string; params?: { name: string; nextPage: string; question: string; subtitle: string | null; options: any[] | null; answer: null; needsImportance: boolean; importance: string | null; ... 7 more ...; index: number; } | undefined; merge?: boolean | undefined; } | ... 4 more ... | { ...; }'.ts(2769)
The code works as I have it but because of the type system I guess it's warning me that it may not in all circumstances? So any help would be appreciated so I don't keep going and build up dozens of error messages
Subreddit
Post Details
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/typescript/...