-
Notifications
You must be signed in to change notification settings - Fork 12.8k
variable assignation types fails for complex types inside array #26674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You probably miss the point of #26673 , whereas the behavior is totally unexpected and differs from In your case, I believe this is how TypeScript works. Giving Maybe a better practice, see if this is what you want to achieve: export interface Link {
type: 'link';
label: string;
url?: string | undefined;
}
export interface Group {
type: 'group';
label: string;
children: Item[] | undefined;
}
export type Item = Group | Link;
export type Index = Item[];
const HomeIndex: Index = [
{ type: 'link', label: 'Home', url: '/' },
{
type: 'group', label: 'Forum', children: [
{ type: 'link', label: 'Topics', url: '/forum/topics/' },
{ type: 'link', label: 'Trending', url: '/forum/trending/' },
{ type: 'link', label: 'Search', url: '/forum/search/' },
]
},
{ type: 'link', label: 'Documents', url: '/documents' },
{ type: 'link', label: 'Downloads', url: '/downloads'},
]; |
Ok great got it. It allowed me to work with nested typed interfaces after defining them as types. This is what I was trying to achieve:
I did not notice this changed. I was able to use this before not sure what version of ts. This is what I did :
|
TypeScript Version: 3.0.1
Search Terms: Advanced Tyoes, Array Types Assignation, Multiple Types Array
Code
Expected behavior:
Type should be allowed for Array
Actual behavior:
Throws error saying type not assignable and a property link/children not available in subtype of the interface
Seems duplicate of following:
#26673
Related Issues:
All assignation types failed
The text was updated successfully, but these errors were encountered: