2
The following code compiles without any type of Warning. It is some configuration that is wrong/missing?
interface CategoryInfo {
name: {
portuguese: string
english: string
spanish: string
}
icon: string
categoryId: number
active: boolean
benefits: number
subscribers: number
createdAt: string
updatedAt: string
deletedAt?: string
}
export function formatFetchCategoriesResponse(
response: CategoryInfo[]
): CategoryInfo[] {
return response.map((category) => ({
...category,
aPropertyThatDoesntExists: 'Anything',
}))
}
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"lib": ["ESNext", "ESNext.AsyncIterable", "DOM"],
"esModuleInterop": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": true,
"experimentalDecorators": true,
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"],
"@/*": ["./src/*"]
},
"types": [
"@types/node",
"@nuxt/types",
"ant-design-vue/types",
"@nuxtjs/axios",
"@nuxtjs/auth-next"
]
},
"exclude": ["node_modules", ".nuxt", "dist"]
}
It’s "working" because the typing is like
any
. https://codesandbox.io/s/typescript-forked-fjk6v?file=/src/index.ts:324-341– Michael Pacheco
Wait, mine’s not like any, or did you mean yours is?
– Vagner Wentz
@Michaelpacheco Do like this, create a typing for your
category
on the map.– Vagner Wentz
By sandbox ta showing that the typing is any. Putting the typing on the map might work but this is a very simple type inference that should work without the need for explicit typing
– Michael Pacheco