diff --git a/crates/oxc_isolated_declarations/src/scope.rs b/crates/oxc_isolated_declarations/src/scope.rs index 94a347ca5..0b95dd379 100644 --- a/crates/oxc_isolated_declarations/src/scope.rs +++ b/crates/oxc_isolated_declarations/src/scope.rs @@ -261,10 +261,9 @@ impl<'a> Visit<'a> for ScopeTree<'a> { } } - /// `type D = { [K in keyof T]: K };` + /// `type D = { [key in keyof T]: K };` /// ^^^^^^^^^^^^^^^^^^^^ - /// `K` is a type parameter - /// We need to add `K` to the scope + /// We need to add both `T` and `K` to the scope fn visit_ts_mapped_type(&mut self, ty: &TSMappedType<'a>) { // copy from walk_ts_mapped_type self.enter_scope(ScopeFlags::empty()); @@ -272,6 +271,9 @@ impl<'a> Visit<'a> for ScopeTree<'a> { if let Some(name) = &ty.name_type { self.visit_ts_type(name); } + if let Some(constraint) = &ty.type_parameter.constraint { + self.visit_ts_type(constraint); + } if let Some(type_annotation) = &ty.type_annotation { self.visit_ts_type(type_annotation); } diff --git a/crates/oxc_isolated_declarations/tests/fixtures/mapped-types.ts b/crates/oxc_isolated_declarations/tests/fixtures/mapped-types.ts new file mode 100644 index 000000000..adcdd2418 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/fixtures/mapped-types.ts @@ -0,0 +1,6 @@ +import {K} from 'foo' +import {T} from 'bar' + +export interface I { + prop: {[key in K]: T} +} \ No newline at end of file diff --git a/crates/oxc_isolated_declarations/tests/snapshots/mapped-types.snap b/crates/oxc_isolated_declarations/tests/snapshots/mapped-types.snap new file mode 100644 index 000000000..1f783ec23 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/snapshots/mapped-types.snap @@ -0,0 +1,11 @@ +--- +source: crates/oxc_isolated_declarations/tests/mod.rs +input_file: crates/oxc_isolated_declarations/tests/fixtures/mapped-types.ts +--- +==================== .D.TS ==================== + +import { K } from 'foo'; +import { T } from 'bar'; +export interface I { + prop: { [key in K] : T}; +}