diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index f921ceca3b..1cb8211e16 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -6,9 +6,9 @@ use stc_ts_errors::{ DebugExt, ErrorKind, }; use stc_ts_types::{ - Array, Conditional, EnumVariant, Index, IndexedAccessType, Instance, Interface, Intersection, IntrinsicKind, Key, KeywordType, LitType, - Mapped, PropertySignature, QueryExpr, QueryType, Readonly, Ref, StringMapping, ThisType, Tuple, TupleElement, Type, TypeElement, - TypeLit, TypeParam, + Array, CommonTypeMetadata, Conditional, EnumVariant, Index, IndexedAccessType, Instance, Interface, Intersection, IntrinsicKind, Key, + KeywordType, KeywordTypeMetadata, LitType, Mapped, PropertySignature, QueryExpr, QueryType, Readonly, Ref, StringMapping, ThisType, + Tuple, TupleElement, Type, TypeElement, TypeLit, TypeParam, }; use stc_utils::{cache::Freeze, dev_span, ext::SpanExt, stack}; use swc_atoms::js_word; @@ -1156,6 +1156,15 @@ impl Analyzer<'_, '_> { } match (to, rhs) { + ( + Type::Tuple(Tuple { elems, .. }), + Type::TypeLit(TypeLit { + span, + members, + metadata, + tracker, + }), + ) => fail!(), (_, Type::Conditional(rc)) => { let new_true_ty = self.overwrite_conditional(span, rc); @@ -1568,6 +1577,25 @@ impl Analyzer<'_, '_> { } } } + + if let RTsLit::Number(_) = &lhs.lit { + if let Type::Keyword(KeywordType { + span, + kind, + metadata: + KeywordTypeMetadata { + common: CommonTypeMetadata { resolved_from_var, .. }, + .. + }, + tracker, + }) = rhs + { + if let (TsKeywordTypeKind::TsNumberKeyword, true) = (kind, resolved_from_var) { + return Ok(()); + } + } + } + fail!() } }, diff --git a/crates/stc_ts_type_checker/tests/conformance/es2022/es2022IntlAPIs.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/es2022/es2022IntlAPIs.error-diff.json new file mode 100644 index 0000000000..b22aa03fb5 --- /dev/null +++ b/crates/stc_ts_type_checker/tests/conformance/es2022/es2022IntlAPIs.error-diff.json @@ -0,0 +1,12 @@ +{ + "required_errors": {}, + "required_error_lines": {}, + "extra_errors": { + "TS2339": 1 + }, + "extra_error_lines": { + "TS2339": [ + 14 + ] + } +} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.errors.json b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.errors.json new file mode 100644 index 0000000000..65faba821d --- /dev/null +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.errors.json @@ -0,0 +1,14 @@ +[ + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility02.ts", + "line": 16, + "column": 0, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility02.ts", + "line": 18, + "column": 0, + "code": "TS2740" + } +] diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.stats.rust-debug new file mode 100644 index 0000000000..780225267c --- /dev/null +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.stats.rust-debug @@ -0,0 +1,6 @@ +Stats { + required_error: 0, + matched_error: 2, + extra_error: 0, + panic: 0, +} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.ts b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.ts new file mode 100644 index 0000000000..1249ffdadf --- /dev/null +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.ts @@ -0,0 +1,20 @@ +interface StrNum extends Array { + 0: string; + 1: number; + length: 2; +} + +var x: [string, number]; +var y: StrNum; +var z: { + 0: string; + 1: number; + length: 2; +}; + +x = y; +x = z; // should get ts2322 +y = x; // should pass +y = z; +z = x; // should pass +z = y;