mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-24 20:23:08 +02:00
Fix types
This commit is contained in:
parent
8b13e3c327
commit
a9fc176c3c
2 changed files with 9 additions and 9 deletions
|
@ -44,9 +44,9 @@ export type Variable = Block & {
|
|||
name: string;
|
||||
};
|
||||
|
||||
export type Type = 'string' | 'number' | 'boolean' | 'stringArray';
|
||||
export type Type = 'string' | 'number' | 'boolean' | 'stringArray' | null;
|
||||
|
||||
export const funcDefs = {
|
||||
export const funcDefs: Record<string, { in: any[]; out: any; category: string; icon: any; }> = {
|
||||
if: { in: ['boolean', 0, 0], out: 0, category: 'flow', icon: faShareAlt, },
|
||||
for: { in: ['number', 'function'], out: null, category: 'flow', icon: faRecycle, },
|
||||
not: { in: ['boolean'], out: 'boolean', category: 'logical', icon: faFlag, },
|
||||
|
@ -81,7 +81,7 @@ export const funcDefs = {
|
|||
seedRandomPick: { in: [null, 0], out: 0, category: 'random', icon: faDice, },
|
||||
};
|
||||
|
||||
export const literalDefs = {
|
||||
export const literalDefs: Record<string, { out: any; category: string; icon: any; }> = {
|
||||
text: { out: 'string', category: 'value', icon: faQuoteRight, },
|
||||
multiLineText: { out: 'string', category: 'value', icon: faAlignLeft, },
|
||||
textList: { out: 'stringArray', category: 'value', icon: faList, },
|
||||
|
@ -105,7 +105,7 @@ export function isFnBlock(block: Block): block is FnBlock {
|
|||
|
||||
export type PageVar = { name: string; value: any; type: Type; };
|
||||
|
||||
export const envVarsDef = {
|
||||
export const envVarsDef: Record<string, Type> = {
|
||||
AI: 'string',
|
||||
URL: 'string',
|
||||
VERSION: 'string',
|
||||
|
|
|
@ -58,7 +58,7 @@ export class ASTypeChecker {
|
|||
}
|
||||
|
||||
@autobind
|
||||
public getExpectedType(v: Block, slot: number): Type | null {
|
||||
public getExpectedType(v: Block, slot: number): Type {
|
||||
const def = funcDefs[v.type];
|
||||
if (def == null) {
|
||||
throw new Error('Unknown type: ' + v.type);
|
||||
|
@ -86,7 +86,7 @@ export class ASTypeChecker {
|
|||
}
|
||||
|
||||
@autobind
|
||||
public infer(v: Block): Type | null {
|
||||
public infer(v: Block): Type {
|
||||
if (v.type === null) return null;
|
||||
if (v.type === 'text') return 'string';
|
||||
if (v.type === 'multiLineText') return 'string';
|
||||
|
@ -140,19 +140,19 @@ export class ASTypeChecker {
|
|||
}
|
||||
|
||||
@autobind
|
||||
public getVarsByType(type: Type | null): Variable[] {
|
||||
public getVarsByType(type: Type): Variable[] {
|
||||
if (type == null) return this.variables;
|
||||
return this.variables.filter(x => (this.infer(x) === null) || (this.infer(x) === type));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public getEnvVarsByType(type: Type | null): string[] {
|
||||
public getEnvVarsByType(type: Type): string[] {
|
||||
if (type == null) return Object.keys(envVarsDef);
|
||||
return Object.entries(envVarsDef).filter(([k, v]) => v === null || type === v).map(([k, v]) => k);
|
||||
}
|
||||
|
||||
@autobind
|
||||
public getPageVarsByType(type: Type | null): string[] {
|
||||
public getPageVarsByType(type: Type): string[] {
|
||||
if (type == null) return this.pageVars.map(v => v.name);
|
||||
return this.pageVars.filter(v => type === v.type).map(v => v.name);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue