Skip to content
This repository was archived by the owner on Oct 15, 2018. It is now read-only.

Latest commit

 

History

History
53 lines (41 loc) · 885 Bytes

File metadata and controls

53 lines (41 loc) · 885 Bytes

Strict Interfaces

Input

interface Person {
    firstName: string;
    lastName: string;
    address?: Address;
}

interface Address {
    firstLine: string;
    secondLine?: string;
    city: string;
}

Code

import {getInfoFromFiles} from "ts-type-info";

const fileName = "input.ts";
const info = getInfoFromFiles([fileName]);
const file = info.getFile(fileName);

file.interfaces.forEach(interfaceDef => {
    info.renameDefinitionAs(interfaceDef, interfaceDef.name + "Strict");

    interfaceDef.properties.forEach(property => {
        property.isOptional = false;
    });
});

const output = file.write();

Output

interface PersonStrict {
    firstName: string;
    lastName: string;
    address: AddressStrict;
}

interface AddressStrict {
    firstLine: string;
    secondLine: string;
    city: string;
}