'type is any' issue thrown from plugin but not from CLI
Closed this issue · 2 comments
geochronology commented
Version(if relevant): 1.0.0
Environment(if relevant): vscode
Code(if relevant):
// test.ts (no issues here)
import {
introducePerson,
Status,
isFulltimeEmployee,
personToString,
getProfessions,
} from "./objects";
const jack = {
name: {
first: "Jack",
last: "Herrington",
},
status: Status.FullTime,
profession: "Engineer",
};
console.log(introducePerson(jack));
console.log(isFulltimeEmployee(jack));
console.log(personToString(jack));
console.log(
getProfessions({
1: jack,
})
);
// objects.ts (issue is here)
export const FullTime = "FullTime";
export const Temporary = "Temporary";
export enum Status {
FullTime,
Temporary
}
type Person = {
name: {
first: string,
middle?: string
last: string,
},
status: Status,
profession: string
}
export const introducePerson = (person: Person) =>
`Hello ${person.name.first} ${person.name.middle} ${person.name.last}`;
export const isFulltimeEmployee = (person: Person) => person.status === Status.FullTime;
export const personToString = (
person: Person = {
status: Status.FullTime,
name: {
first: "unknown",
last: "unknown",
},
profession: "unknown",
}
) => JSON.stringify(person, null, 2);
type PersonMap = { [key: number]: Person }
export const getProfessions = (personMap: PersonMap) =>
Object.values(personMap)
.map(({ profession }) => profession) // <=== this is the line that throws "The type of 'profession' is 'any'" in vscode
.join("\n");
Expected: consistent results with plugin and npm module
Actual: Since type-coverage results in a 100% score using the above code, either the plugin is flagging this line inaccurately OR the type-coverage npm module is failing to catch it.
plantain-00 commented
It is any
as typescript suggests:
The Object.values()
is the root cause, I can fix it by add tsconfig.json
in the project root directory:
{
"compilerOptions": {
"target": "es2017"
}
}
You can try to add tsconfig.json
(extends
your CLI tsconfig.json
) in the project root directory.
I will add it in the document later.
geochronology commented
Thanks for clarifying!