ts-expand
v2.0.2
Published
This is Typescript Type Like Loadash
Downloads
18
Readme
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)