After using @babel/parser to parse some string and getting a ast, I encouter an error when logging the ast by the type of obj.prop, but it work when use the type of obj['prop']
import { parse } from "@babel/parser";
import traverse from "@babel/traverse";
const ast = parse('{key: "something"}', {
sourceType: "module",
plugins: ["typescript"],
});
// Property 'declaration' does not exist on type 'Statement'. Property 'declaration' does not exist on type 'BlockStatement'.ts(2339)
console.log(ast.program.body[0].declaration.properties);
// it's good
console.log(ast.program.body[0]["declaration"].properties);
I'm confused about the difference of the two type writing?
thanks for answer