Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// tslint:disable-next-line:variable-name
const Name = convertConstraint(nameConstraint);
type Name = InstanceType;
const ageConstraint = NumberType.withConstraint(n => {
return Number.isInteger(n) && n >= 0;
});
// tslint:disable-next-line:variable-name
const Age = convertConstraint(ageConstraint);
type Age = InstanceType;
const personRecord = Record({
name: nameConstraint,
age: ageConstraint,
kind: Literal('$person')
});
// tslint:disable-next-line:variable-name
const Person = convertConstraint(personRecord);
type Person = Static;
dynamo.add(Name, Age, Person);
class CreatePerson {
@signature()
person(name: Name, age: Age): Person {
return { name, age, kind: '$person' };
}
}
const createPerson = dynamo.function(CreatePerson);
constraint['name'] = name ? `${name} ${constraint['tag']}` : constraint['tag'];
guard()(constraint, 'guard');
return constraint as any;
}
const dynamo = new Dynamo();
const nameConstraint = StringType.withConstraint(x => {
return x.length > 0;
});
// tslint:disable-next-line:variable-name
const Name = convertConstraint(nameConstraint);
type Name = InstanceType;
const ageConstraint = NumberType.withConstraint(n => {
return Number.isInteger(n) && n >= 0;
});
// tslint:disable-next-line:variable-name
const Age = convertConstraint(ageConstraint);
type Age = InstanceType;
const personRecord = Record({
name: nameConstraint,
age: ageConstraint,
kind: Literal('$person')
});
// tslint:disable-next-line:variable-name
const Person = convertConstraint(personRecord);
type Person = Static;
import { assert, IsExact } from 'conditional-type-checks';
interface ConstraintToken extends Constraint {
name: string;
new(...args: any[]): V;
}
function convertConstraint>(constraint: T, name?: string): ConstraintToken> {
constraint['name'] = name ? `${name} ${constraint['tag']}` : constraint['tag'];
guard()(constraint, 'guard');
return constraint as any;
}
const dynamo = new Dynamo();
const nameConstraint = StringType.withConstraint(x => {
return x.length > 0;
});
// tslint:disable-next-line:variable-name
const Name = convertConstraint(nameConstraint);
type Name = InstanceType;
const ageConstraint = NumberType.withConstraint(n => {
return Number.isInteger(n) && n >= 0;
});
// tslint:disable-next-line:variable-name
const Age = convertConstraint(ageConstraint);
type Age = InstanceType;
const personRecord = Record({
import { Static, Union, Literal, match } from 'runtypes';
// Define the runtype
const Day = Union(
Literal('Sunday'),
Literal('Monday'),
Literal('Tuesday'),
Literal('Wednesday'),
Literal('Thursday'),
Literal('Friday'),
Literal('Saturday'),
);
// Extract the static type
type Day = Static; // = 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday'
// Extract enumerated literal values
const days: Day[] = Day.alternatives.map(lit => lit.value);
for (const day of days) {
console.log(`Good morning, it's ${day}!`);
}
Literal('Thursday'),
Literal('Friday'),
Literal('Saturday'),
);
// Extract the static type
type Day = Static; // = 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday'
// Extract enumerated literal values
const days: Day[] = Day.alternatives.map(lit => lit.value);
for (const day of days) {
console.log(`Good morning, it's ${day}!`);
}
const isWeekend = match(
[Literal('Sunday'), () => true],
[Literal('Saturday'), () => true],
[Day, () => false],
);
});
type Planet = Static<
typeof Planet
>; /* = {
type: 'planet';
location: Vector;
mass: NonNegative;
population: NonNegative;
habitable: Boolean;
}*/
const Rank = Union(
Literal('captain'),
Literal('first mate'),
Literal('officer'),
Literal('ensign'),
);
type Rank = Static; // = 'captain' | 'first mate' | 'officer' | 'ensign'
const CrewMember = Record({
name: String,
age: NonNegative,
rank: Rank,
home: Planet,
});
type CrewMember = Static<
typeof CrewMember
>; /* = {
name: string;
age: NonNegative;
rank: Rank;
home: Planet;
const CrewMember = Record({
name: String,
age: NonNegative,
rank: Rank,
home: Planet,
});
type CrewMember = Static<
typeof CrewMember
>; /* = {
name: string;
age: NonNegative;
rank: Rank;
home: Planet;
}*/
const Ship = Record({
type: Literal('ship'),
location: Vector,
mass: NonNegative,
name: String,
crew: Array(CrewMember),
});
type Ship = Static<
typeof Ship
>; /* = {
type: 'ship';
location: Vector;
mass: NonNegative;
name: string;
crew: CrewMember[];
}*/
trendingDaily: Number,
trendingWeekly: Number,
trendingMonthly: Number,
}).And(
// Optional properties.
Partial({
displayName: String.Or(Null),
shortDescription: String.Or(Null),
repositoryUrl: String.Or(Null),
}),
)
export const PackageJSONRuntime = Record({
contributes: Record({
themes: Array(
Record({
path: String,
}).And(
Partial({
label: String,
uiTheme: String,
}),
),
),
}),
})
export const ThemeTypeRuntime = Union(
Literal('light'),
Literal('dark'),
Literal('hc'),
)
import { Static, Union, Literal, match } from 'runtypes';
// Define the runtype
const Day = Union(
Literal('Sunday'),
Literal('Monday'),
Literal('Tuesday'),
Literal('Wednesday'),
Literal('Thursday'),
Literal('Friday'),
Literal('Saturday'),
);
// Extract the static type
type Day = Static; // = 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday'
// Extract enumerated literal values
const days: Day[] = Day.alternatives.map(lit => lit.value);
for (const day of days) {
export const ColorsRuntime = Partial({
// These colors may not exist in the object but also may be null.
activityBarBackground: String.Or(Null),
activityBarForeground: String.Or(Null),
activityBarBorder: String.Or(Null),
statusBarBackground: String.Or(Null),
statusBarForeground: String.Or(Null),
editorBackground: String.Or(Null),
editorForeground: String.Or(Null),
editorGroupHeaderTabsBackground: String.Or(Null),
editorLineNumberForeground: String.Or(Null),
tabActiveBackground: String.Or(Null),
tabActiveForeground: String.Or(Null),
tabInactiveBackground: String.Or(Null),
tabInactiveForeground: String.Or(Null),
editorGroupHeaderTabsBorder: String.Or(Null),
tabActiveBorder: String.Or(Null),
tabBorder: String.Or(Null),
contrastActiveBorder: String.Or(Null),
contrastBorder: String.Or(Null),
titleBarActiveBackground: String.Or(Null),
titleBarActiveForeground: String.Or(Null),
titleBarInactiveBackground: String.Or(Null),
titleBarInactiveForeground: String.Or(Null),
titleBarBorder: String.Or(Null),
})
export const LineTokenRuntime = Record({
token: String,
style: Partial({
color: String,
fontWeight: String,