Skip to content

Commit

Permalink
feature: @putout/printer: TSTypeParameter inside TSMappedType: extend…
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Oct 5, 2023
1 parent 35a1406 commit 8e5d5f5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/tokenize/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const {isNext} = require('../is');
const {TSTypeLiteral} = require('./type/ts-type-literal');
const {TSTypeAliasDeclaration} = require('./type/ts-type-alias-declaration');
const {TSMappedType} = require('./ts-mapped-type');
const {TSMappedType} = require('./mapped-type/ts-mapped-type');
const {TSConditionalType} = require('./ts-conditional-type');
const {TSTypeParameter} = require('./type/ts-type-parameter');
const {TSDeclareFunction} = require('./function/ts-declare-function');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Status = 'active';

const data: {
[key in Status]: null;
} = {
active: null,
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const {extend} = require('supertape');
const {printExtension} = require('../../../test/printer');
const {readFixtures} = require('../../../test/fixture');
const {printExtension} = require('../../../../test/printer');
const {readFixtures} = require('../../../../test/fixture');
const fixture = readFixtures(__dirname);

const test = extend({
Expand All @@ -13,3 +13,8 @@ test('printer: tokenizer: typescript: TSMappedType: nameType', (t) => {
t.print(fixture.tsMappedTypeNameType);
t.end();
});

test('printer: tokenizer: typescript: TSMappedType: in', (t) => {
t.print(fixture.tsMappedTypeIn);
t.end();
});
2 changes: 1 addition & 1 deletion lib/tokenize/typescript/type/ts-type-parameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports.TSTypeParameter = (path, {write, traverse}) => {
if (!exists(constraint))
return;

if (constraint.isTSTypeOperator()) {
if (constraint.isTSTypeOperator() || path.parentPath.isTSMappedType()) {
write(' in ');
} else {
write(' extends ');
Expand Down

0 comments on commit 8e5d5f5

Please sign in to comment.