diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5b8504eb6dc..3209f234f85 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2986,7 +2986,7 @@ namespace ts { return parseFunctionOrConstructorType(SyntaxKind.ConstructorType); } const type = parseUnionTypeOrHigher(); - if (!noConditionalTypes && parseOptional(SyntaxKind.ExtendsKeyword)) { + if (!noConditionalTypes && !scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.ExtendsKeyword)) { const node = createNode(SyntaxKind.ConditionalType, type.pos); node.checkType = type; // The type following 'extends' is not permitted to be another conditional type diff --git a/tests/baselines/reference/conditionalTypesASI.js b/tests/baselines/reference/conditionalTypesASI.js new file mode 100644 index 00000000000..0399d30f153 --- /dev/null +++ b/tests/baselines/reference/conditionalTypesASI.js @@ -0,0 +1,18 @@ +//// [conditionalTypesASI.ts] +// Repro from #21637 + +interface JSONSchema4 { + a?: number + extends?: string | string[] +} + + +//// [conditionalTypesASI.js] +// Repro from #21637 + + +//// [conditionalTypesASI.d.ts] +interface JSONSchema4 { + a?: number; + extends?: string | string[]; +} diff --git a/tests/baselines/reference/conditionalTypesASI.symbols b/tests/baselines/reference/conditionalTypesASI.symbols new file mode 100644 index 00000000000..00480cba82b --- /dev/null +++ b/tests/baselines/reference/conditionalTypesASI.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/conditionalTypesASI.ts === +// Repro from #21637 + +interface JSONSchema4 { +>JSONSchema4 : Symbol(JSONSchema4, Decl(conditionalTypesASI.ts, 0, 0)) + + a?: number +>a : Symbol(JSONSchema4.a, Decl(conditionalTypesASI.ts, 2, 23)) + + extends?: string | string[] +>extends : Symbol(JSONSchema4.extends, Decl(conditionalTypesASI.ts, 3, 12)) +} + diff --git a/tests/baselines/reference/conditionalTypesASI.types b/tests/baselines/reference/conditionalTypesASI.types new file mode 100644 index 00000000000..b0ee4502cfc --- /dev/null +++ b/tests/baselines/reference/conditionalTypesASI.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/conditionalTypesASI.ts === +// Repro from #21637 + +interface JSONSchema4 { +>JSONSchema4 : JSONSchema4 + + a?: number +>a : number + + extends?: string | string[] +>extends : string | string[] +} + diff --git a/tests/cases/compiler/conditionalTypesASI.ts b/tests/cases/compiler/conditionalTypesASI.ts new file mode 100644 index 00000000000..44d6d816851 --- /dev/null +++ b/tests/cases/compiler/conditionalTypesASI.ts @@ -0,0 +1,8 @@ +// @declaration: true + +// Repro from #21637 + +interface JSONSchema4 { + a?: number + extends?: string | string[] +}