{"id":19370,"library":"babel-type-scopes","title":"babel-type-scopes","description":"Utility functions for looking up and working with Flow and TypeScript type scopes in Babel. Version 1.1.0 provides four main functions: isTypeScope, getClosestTypeScopePath, getOwnTypeBindings, and getTypeBinding. These helpers identify whether a Babel path creates a type scope, find the nearest ancestor type scope, retrieve type bindings defined in the current scope, and search for type bindings up the scope chain. The package supports both Flow and TypeScript, and is intended for Babel plugin or tool authors. It is lightweight with no production dependencies. Released in 2018, the library is stable but sees infrequent updates. Similar functionality exists in @babel/traverse, but this package provides more targeted scope inspection.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/babel-utils/babel-type-scopes","tags":["javascript","babel","utils","flow","typescript","scope","binding"],"install":[{"cmd":"npm install babel-type-scopes","lang":"bash","label":"npm"},{"cmd":"yarn add babel-type-scopes","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-type-scopes","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Correct named import. The package is ESM-only; require will not work without transpilation.","wrong":"const isTypeScope = require('babel-type-scopes').isTypeScope","symbol":"isTypeScope","correct":"import { isTypeScope } from 'babel-type-scopes'"},{"note":"Named export, not default export.","wrong":"import getClosestTypeScopePath from 'babel-type-scopes'","symbol":"getClosestTypeScopePath","correct":"import { getClosestTypeScopePath } from 'babel-type-scopes'"},{"note":"CommonJS require with destructuring is possible if you use a bundler, but ESM import is recommended.","wrong":"const { getTypeBinding } = require('babel-type-scopes')","symbol":"getTypeBinding","correct":"import { getTypeBinding } from 'babel-type-scopes'"}],"quickstart":{"code":"import { isTypeScope, getClosestTypeScopePath, getOwnTypeBindings, getTypeBinding } from 'babel-type-scopes';\nimport { parse } from '@babel/parser';\nimport traverse from '@babel/traverse';\n\nconst code = `type Foo = string; let x: Foo = 'hello';`;\nconst ast = parse(code, { plugins: ['typescript'] });\ntraverse(ast, {\n  TSTypeAliasDeclaration(path) {\n    console.log(isTypeScope(path)); // true\n    const scopePath = getClosestTypeScopePath(path);\n    console.log(scopePath.node.type); // TSTypeAliasDeclaration\n    const bindings = getOwnTypeBindings(scopePath);\n    console.log(Object.keys(bindings)); // ['Foo']\n    const binding = getTypeBinding(path, 'Foo');\n    console.log(binding.kind); // 'declaration'\n  }\n});","lang":"typescript","description":"Parses TypeScript code, traverses AST, and demonstrates each exported function on a type alias."},"warnings":[{"fix":"Use @babel/traverse's getBinding for non-type bindings.","message":"The package only considers type scopes (type declarations, interface, etc.). Regular variable scopes are not covered.","severity":"gotcha","affected_versions":"<=1.1.0"},{"fix":"Check if the returned path is the same as the input; if so, the path itself is a type scope.","message":"getClosestTypeScopePath may return the current path if it is a type scope, which may be unexpected.","severity":"gotcha","affected_versions":"all"},{"fix":"Use getTypeBinding only for type-level bindings (types, interfaces). For value bindings, use @babel/traverse's scope.getBinding.","message":"getTypeBinding searches only type scopes; it does not look up regular bindings. This may cause confusion if a binding is declared with 'let' or 'const'.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install babel-type-scopes' or 'yarn add babel-type-scopes'.","cause":"Package not installed or missing from node_modules.","error":"Cannot find module 'babel-type-scopes'"},{"fix":"Use 'import { isTypeScope } from 'babel-type-scopes';'","cause":"Incorrect import syntax (e.g., default import instead of named import).","error":"TypeError: isTypeScope is not a function"},{"fix":"Ensure the name exists as a type binding; consider checking getOwnTypeBindings first.","cause":"No type binding found in the scope chain for the given name.","error":"TypeError: Cannot read property 'kind' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}