Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

feat: typescript options #1940

Merged
merged 3 commits into from
Nov 16, 2021
Merged

feat: typescript options #1940

merged 3 commits into from
Nov 16, 2021

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Nov 15, 2021

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

  • Support options.typescript
    • strict (default is false)
    • tsConfig (allow overriding generated tsconfig defaults)
    • [placeholder] typeCheck (#1818)
  • Strict mode is disabled by default allowing users to progressively update their codebase and learn ts
  • Add note about strict typechecking in concepts > typescript

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pi0 pi0 requested a review from danielroe November 15, 2021 18:57
@netlify
Copy link

netlify bot commented Nov 15, 2021

βœ”οΈ Deploy Preview for nuxt3-docs ready!

πŸ”¨ Explore the source changes: 36580e3

πŸ” Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/6192adb4bc6d3a000854fc0f

😎 Browse the preview: https://deploy-preview-1940--nuxt3-docs.netlify.app


/**
* You can extend generated `.nuxt/tsconfig.json` using this option
* @typedef {Awaited<ReturnType<typeof import('pkg-types')['readPackageJSON']>>}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @danielroe This was only possible could find to type with the current version of untyped :D typeof import('pkg-types).TSConfig apparently is not working since is a type-only export

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not type this as TSConfig from import type { TSConfig } from 'pkg-types' with typescript?
Then @typedef isn't even that important anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not for internally typing. We use untyped to auto-generate docs and type definitions out of the source like this: https://unpkg.com/browse/@nuxt/kit-edge@3.0.0-27284440.b16cfea/schema/config.d.ts -- Currently untyped cannot generate import type { } statements on top of the file.

compilerOptions: {
target: 'ESNext',
module: 'ESNext',
moduleResolution: 'Node',
skipLibCheck: true,
strict: true,
strict: nuxt.options.typescript.strict,
Copy link
Member Author

@pi0 pi0 Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hidden fix: I tried to put it as defaults in typescript.compilerOptions in schema but untyped had strange behavior with $resolve. Have to check more in-depth making reproduction (this can potentially make unwanted behavior on other resolve fns)

@pi0 pi0 merged commit b16cfea into main Nov 16, 2021
@pi0 pi0 deleted the fix/strict-ts branch November 16, 2021 12:32
@nandi95
Copy link
Contributor

nandi95 commented Nov 16, 2021

I know it's a bit late to the party but I think the default strict should be true. And people who progressively upgrade should turn this off if they need to. That is to encourage strictness by default in the community and not have a "breaking" change if and when this is turned back to true later down the line.

@pi0
Copy link
Member Author

pi0 commented Nov 16, 2021

I know it's a bit late to the party but I think the default strict should be true. And people who progressively upgrade should turn this off if they need to. That is to encourage strictness by default in the community and not have a "breaking" change if and when this is turned back to true later down the line.

While I understand your perspective, this does apply to the majority of users that use typescript. Strict mode is disabled in typescript itself for a good reason allowing users to "Adopt TypeScript Gradually" by design (https://www.typescriptlang.org/). Most of the users can get much more type-safety than js when using ts and an advanced section of users can opt-in.

Also with strict mode enabled, upgrading the typescript version is more likely of having breaking changes.

Disabling by default also makes Nuxt ensure DX-related futures are not hard on strict mode assumption and always work of all ts users.

@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants