Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

ts-expand

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-expand

This is Typescript Type Like Loadash

latest
npmnpm
Version
2.0.2
Version published
Maintainers
1
Created
Source

ts-expand

Operate TS type as loadash

introduce

install

npm install ts-expand

use

import * as _ from 'ts-expand'

interface Person {
  name: string
  age: number
  sex: string
  other: Symbol
}

const nameInfo: _.Filter<Person, 'name'> = {
  name: 'hello world'
}

types

'_.' can find all types

tssql

  • only support 'and'
  • only support 'key'、'is_readonly'、'is_require'
  • ignore case
import * as _ from 'ts-expand'

interface Person {
  readonly name: string
  age: number
  sex?: string
  other: Symbol
}

type SubPerson = _.TsSql(`select * from ? where key = ?`, Person)

// result:
/**
 * SubPerson = {
 *  readonly name: string
    age: number
    sex?: string
    other: Symbol
 * }
 */
type SubPerson_1 = _.TsSql(`select * from ? where key = ?`, Person, 'name' | 'age')

// result:
/**
 * SubPerson_1 = {
 *  readonly name: string
 *  age: number
 * }
 */

type SubPerson_2 = _.TsSql(`select * from ? where key = ? and is_require`, Person)
// result:
/**
 * SubPerson_2 = {
 *  readonly name: string
 *  age: number
 *  other: Symbol
 * }
 */

type SubPerson_3 = _.TsSql(`select * from ? where key = ? and is_require and is_readonly`, Person)

// result:
/**
 * SubPerson_3 = {
 *  readonly name: string
 * }
 */


// TsSqlV2

type SubPerson = _.TsSqlV2(`
  select
    name, age
  from
    ?
  where
    is_require
`, Test)

// result:
/**
 * SubPerson_1 = {
 *  readonly name: string
 *  age: number
 * }
 */

type SubPerson_all = _.TsSqlV2('select * from ?', Test)

Keywords

typescript

FAQs

Package last updated on 05 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts