Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

directives > ToStringOptions not working as expected #389

Closed
skoblenick opened this issue May 13, 2022 · 1 comment
Closed

directives > ToStringOptions not working as expected #389

skoblenick opened this issue May 13, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@skoblenick
Copy link

Describe the bug

To Reproduce

  1. setup the project

    mkdir yaml-issue && cd $_
    npm init -y
    npm i -D yaml@2.0.1
    touch index.ts
    
  2. Add the following code to index.ts:

    import fs from 'fs';
    import path from 'path';
    import { parse, stringify } from 'yaml';
    
    const jsonConfig = {
       name: {
          firstName: 'Johnny',
          lastName: 'Appleseed'
       } 
    };
    
    const yamlConfig = stringify(jsonConfig, null, {
        directives: true,
      });
    
    fs.writeFileSync(path.resolve(__dirname, './config.yml'), yamlConfig);
    
  3. Run the script from terminal:

    $ npx ts-node $PWD/index.ts
    
        return new TSError(diagnosticText, diagnosticCodes);
               ^
    TSError: ⨯ Unable to compile TypeScript:
    index.ts:13:3 - error TS2322: Type 'true' is not assignable to type '(Directives & (boolean | null)) | undefined'.
    
    13   directives: true,
    

Expected behaviour

Expect to be able to set the value to the value of true as documented here https://eemeli.org/yaml/#tostring-options
so that the addition is done at --- the top of the yaml file.

Versions (please complete the following information):

  • Environment: [e.g. Node.js 14.7.0 or Chrome 87.0]
  • yaml: 2.0.1
  • node: 14.18.2
  • ts-node: 10.0.0
@skoblenick skoblenick added the bug Something isn't working label May 13, 2022
@eemeli eemeli closed this as completed in a918afa May 14, 2022
@eemeli
Copy link
Owner

eemeli commented May 14, 2022

Thank you for reporting this! There was an internal document option used only by the composer with the same directives name. That's now been renamed as _directives so that the TS types don't conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants