Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[PoC] Gentype emit TS assertions to let TS validate that bindings are correct#7879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
zth wants to merge2 commits intomaster
base:master
Choose a base branch
Loading
fromgentype-satisfies

Conversation

@zth
Copy link
Member

@zthzth commentedSep 12, 2025
edited
Loading

Papaparse.res:

@gentype.satisfies(("papaparse","ParseError"))typeparseError= {/** A generalization of the error */  @as("type")type_: [#Quotes |#Delimiter |#FieldMismatch],/** Standardized error code */code: [#MissingQuotes |#UndetectableDelimiter |#TooFewFields |#TooManyFields |#InvalidQuotes],/** Human-readable details */message:string,/** Row index of parsed data where error is */row?:int,/** Index within the row where error is */index?:int,}@gentype.satisfies(("papaparse","ParseMeta"))typeparseMeta= {/** Delimiter used */delimiter:string,/** Line break sequence used */linebreak:string,/** Whether process was aborted */aborted:bool,/** Array of field names */fields?:array<string>,/** Whether preview consumed all input */truncated:bool,cursor:float,}@gentype.satisfies(("papaparse","ParseResult"))typeparseResult<'t>= {/**     * an array of rows. If header is false, rows are arrays; otherwise they are objects of data keyed by the field name.     */data:array<'t>,/** an array of errors. */errors:array<parseError>,/**     * contains extra information about the parse, such as delimiter used,     * the newline sequence, whether the process was aborted, etc.     * Properties in this object are not guaranteed to exist in all situations.     */meta:parseMeta,}@gentype.satisfies(("papaparse","parse")) @module("papaparse")externalparseCsvString:string=>parseResult<'t>="parse"

EmitsPapaparse.assertions.ts:

export{};type$RescriptTypeSatisfiesTypeScriptType<RescriptTypeextendsTypeScriptType,TypeScriptType>=RescriptType;typeparseError=$RescriptTypeSatisfiesTypeScriptType<{/** A generalization of the error */readonlytype:"Delimiter"|"FieldMismatch"|"Quotes";/** Standardized error code */readonlycode:"TooManyFields"|"MissingQuotes"|"UndetectableDelimiter"|"TooFewFields"|"InvalidQuotes";/** Human-readable details */readonlymessage:string;/** Row index of parsed data where error is */readonlyrow?:number;/** Index within the row where error is */readonlyindex?:number},import("papaparse").ParseError>;typeparseMeta=$RescriptTypeSatisfiesTypeScriptType<{/** Delimiter used */readonlydelimiter:string;/** Line break sequence used */readonlylinebreak:string;/** Whether process was aborted */readonlyaborted:boolean;/** Array of field names */readonlyfields?:string[];/** Whether preview consumed all input */readonlytruncated:boolean;readonlycursor:number},import("papaparse").ParseMeta>;typeparseResult<t>=$RescriptTypeSatisfiesTypeScriptType<{/** * an array of rows. If header is false, rows are arrays; otherwise they are objects of data keyed by the field name. */readonlydata:t[];/** an array of errors. */readonlyerrors:parseError[];/** * contains extra information about the parse, such as delimiter used,     * the newline sequence, whether the process was aborted, etc.     * Properties in this object are not guaranteed to exist in all situations. */readonlymeta:parseMeta},import("papaparse").ParseResult<t>>;constparse=undefinedasunknownastypeofimport("papaparse").parsesatisfies<t>(_1:string)=>parseResult<t>;

This lets TypeScript typecheck that the bindings you've written inPapaparse.res is correct.

Very messy code and needs a bunch of cleanup. That can be done if this is an interesting direction that works out in practice.

@pkg-pr-new
Copy link

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7879

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7879

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7879

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7879

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7879

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@7879

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7879

commit:eed7f63

@zthzth added this to thev12.1 milestoneOct 27, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

v12.1

Development

Successfully merging this pull request may close these issues.

2 participants

@zth

[8]ページ先頭

©2009-2025 Movatter.jp